/**
 * Created by sjg on 17/2/13.
 */

var express = require('express');
var router = express.Router();
var superagent = require('superagent');// 使用了superagent来发起请求

var CONFIG = require('../../../common/config');
var CODE = require('../../../common/code');
var tg3Util = require('../util/tg3Util.js');
var checkUtil = require('../util/checkUtil');
var StaticizeUtil = require('../../../common/util/StaticizeUtil');
var luaSearchUtil = require('../util/luaSearchUtil');
var javaSearchProjectUtil = require('../../yjsc/v2/util/javaSearchProjectUtil');
var luaUtil = require('../../yjsc/v2/util/luaUtil');

var async = require( 'async'); // 同步控制
var moment = require('moment');  // 日期格式化


function ret_func(success, msg, data, res){
    var obj = {
        success: success,
        msg: msg,
        data: data
    };
    // 返回
    res.set('Content-Type', 'application/json');
    res.json(obj);
}

//-------------------------------------接口修改, 模拟修改--------------------------------------------
// 对应老接口: /tg3/getMainPage
function getMainPage_v5_1(req, res, next) {

    //var data = {"hotsBusinessCard":{"list":[{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/125048763_VklJ7QGTZPixnRPIkewC.jpg","id":56,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/123755826_oA8xSnUw8ftcZyl9wGZo.jpg","id":52,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/123529924_qCMLw4bsRRcIJgyOwJxR.jpg","id":51,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/120812416_hlhmpfKw8gBfiSGjgorL.jpg","id":50,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/110525602_qpYgK16iivXvC3tW0e2u.jpg","id":42,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/102942370_9Bx9pcQXKTmh4P5gB0de.jpg","id":36,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/102650265_mtYWn4840q8VterDhuty.jpg","id":35,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/101316667_zXNfcAuLIZZ6zdhnzRi6.jpg","id":32,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/095739604_LKOcPzEMrBHxLJn6bwzu.jpg","id":30,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/095555782_sBKduzplJRkgFbe0GlIg.jpg","id":29,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/143845126_mjhPrXmZS06sWyT8LIm6.jpg","id":24,"desc":"98元/500张起"},{"typeL":4,"title":"商务办公名片限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/143727606_yJt9jSB5BrXoMbSV5C9F.jpg","id":23,"desc":"98元/500张起"}],"title":"热门名片"},"poseterTypeM":[{"id":10,"name":"邀请函","icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoopPrint.jpg"},{"id":20,"name":"促销","icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoopPrint.jpg"},{"id":50,"name":"推广","icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoopPrint.jpg"},{"id":80,"name":"其它","icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoopPrint.jpg"}],"hotsPoster":{"list":[{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/08/110253868_lU0U2IJjTsSePDGNSf2L/0.jpg","id":518,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/07/175602696_qRtp4fr8dqugQbp4EYh7/0.jpg","id":516,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/07/153525097_fBkxBZpSet3FHB9K9CWS/0.jpg","id":515,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/07/125958506_mH1vQNMs39phfHwUUJzj/0.jpg","id":514,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/07/124358282_p8yoDgOSgSFIT66Z8Wz4/0.jpg","id":513,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/170619565_CcO3rScnFsxqKM0HvjqP/0.jpg","id":512,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/162752771_evKtqh0Yhp1oecXCnJRg/0.jpg","id":511,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/06/162506654_rSxpK7gpVrI02EUz3gHB/0.jpg","id":510,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/131828121_ai6jpQxPzYlOzHGtcWNC/0.jpg","id":509,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/131042500_9dqHkdSHitAguANzxhW6/0.jpg","id":508,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/06/105747117_oUrB7CKahhJeiFx39KNL/0.jpg","id":507,"desc":"免费"},{"typeL":1,"title":"商务办海报限时特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/014035180_OYr5eBqVzwTeiXMqU5Xo/0.jpg","id":506,"desc":"免费"}],"title":"热门海报"},"bottomInfo":{"desc":"www.itbour.com","title":"网页版已经上线, 制作更加轻松快捷~"},"hotsSearch":"交通","adInfo":[{"typeL":0,"kind":1,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoop2017.jpg","title":"轮播1","url":"","id":0},{"typeL":0,"kind":1,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoopPrint.jpg","title":"轮播2","url":"","id":0},{"typeL":3,"kind":3,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U126431/2017/02/07/143218134_rzJH8bZDqmVUUHGPNPga.jpg","title":"产品推广","url":"","id":18,"desc":"热门PPT"},{"typeL":1,"kind":3,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U126431/2017/02/07/135057537_MoDsvbNHDmVqrZdOZPxs.jpg","title":"求职招聘","url":"","id":19,"desc":"热门海报"},{"typeL":1,"kind":3,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U126431/2017/02/07/165354054_t7EznOshfIoSqGuzbY9f.jpg","title":"节日祝福","url":"","id":23,"desc":"节日祝福"}],"hotsPPT":{"list":[{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/21/170815615_4wGu6c9yKxlNmOhZDOtD/0.jpg","id":4183,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/20/120646075_V9c1PmO8uXgTtsAcf7zo/0.jpg","id":4182,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/21/164054877_p5oP7XsShoxOyZlztAVD/0.jpg","id":4181,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/20/113948374_3W381dQWVvZEJycn3aDY/0.jpg","id":4180,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/21/161328292_j4fqfU2eSB86Ws47bgOI/0.jpg","id":4179,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/13/145117805_Un3fcdoAlNCaj4yVAu75/0.jpg","id":4178,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U4/2017/01/14/161701937_fKCKtkTKUS0ztJXY5bGM/0.jpg","id":4176,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/14/105204234_4wt3AqZNJtYTufKxLHLj/0.jpg","id":4175,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/13/180429224_zUh75rJTe0akWwJSj00x/0.jpg","id":4174,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U4/2017/01/14/160017713_qGkHfPX6P7SiSdqZkPB3/0.jpg","id":4173,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/13/181911226_cjXWINpToIzbj02Lk78N/0.jpg","id":4172,"desc":"免费"},{"typeL":3,"title":"商务办公幻灯片现实特惠","thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/06/154313742_derkWm0OiWxuqMIAPfIX/0.jpg","id":4171,"desc":"免费"}],"title":"热门幻灯片"},"hotsLeaflet":{"list":[{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/21/101650910_hmeIddRiOvyKigqGGsao.jpg","id":74,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/165111597_zFMEqwXCnt4XjLLSf3Yi.jpg","id":71,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/164935937_AR1pskirDugOxdXGHqb4.jpg","id":70,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/164638068_wg7aOB15d4o5ia3LRjeM.jpg","id":69,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144906941_9sH0bSBTAGNHtaOBciwG.jpg","id":67,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144747327_4168yO09UforziBMRyaP.jpg","id":66,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144603542_Tc4w3IrCmhOSkR3DEVkD.jpg","id":65,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/161615559_L5L3lMGEWcx5mMRStP2u.jpg","id":64,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/161457505_hTaLF1nV37HRmYV7uHVW.jpg","id":63,"desc":"98元/500张起"},{"typeL":4,"title":"传单限时特惠","thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/175519270_m3V0rZ3UAXFLPAQEGN5R.jpg","id":26,"desc":"98元/500张起"}],"title":"热门传单"}};
    //return ret_func(1, CODE.OPERATION_SUCCESS, data, res);


    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var typeL = Number(req.body.typeL || req.query.typeL || '1');

    async.series([
            function(callback){
                tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
            },
            function(callback){
                tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)});//*** results[1]
            },
            function(callback){
                //tg3Util.get_hotsProject(function(error,data){ callback(error,data)});//*** results[2]
                callback(null,null);
            },
            function(callback){
                tg3Util.get_hotsPPT(function(error,data){ callback(error,data)});//*** results[3]
            },
            function(callback){
                tg3Util.get_hotsPoster(function(error,data){ callback(error,data)});//*** results[4]
            },
            function(callback){
                tg3Util.get_hotsMultiPage(function(error,data){ callback(error,data)});//*** results[5]
            },
            function(callback){
                tg3Util.get_hotsBusinessCard(function(error,data){ callback(error,data)});//*** results[6]
            },
            function(callback){
                tg3Util.get_hotsLeaflet(function(error,data){ callback(error,data)});//*** results[7]
            },
            function(callback){
                tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[8]
            },
            function(callback){
                tg3Util.get_multiPageTypeM(function(error,data){ callback(error,data)});//*** results[9]
            },
            function(callback){
                tg3Util.get_bottomInfo(function(error,data){ callback(error,data)});//*** results[10]
            },
            function (callback) {
                callback(null, null)    //***11
            },
            function (callback) {
                tg3Util.get_hotsDisplayRack_v5(function(error, data){callback(error,data)});//*** results[12]
            }
        ],

        function(err, results){
            if(err){
                console.log(err);
                return tg3Util.ret_func_json(0,'error',{},res);
            }

            var printTypeMs = [{"id":40100,"name":"名片","icon":""},{"id":40200,"name":"传单","icon":""}];
            var data = {
                "hotsSearch":       results[0].length>0?results[0][0]:'',
                "adInfo":           results[1],
                //"hotsProject":      {title:"热门专题", list:results[2]},
                "hotsPPT":          {title:"热门幻灯片", list:results[3]},
                "hotsPoster":       {title:"热门海报", list:results[4]},
                "hotsMultiPage":    {title:"热门多页", list:results[5]},
                "hotsBusinessCard": {title:"热门名片", list:results[6]},
                "hotsLeaflet":      {title:"热门传单", list:results[7]},
                "poseterTypeM":     results[8],
                "multiPageTypeM":   results[9],
                "bottomInfo":       results[10],
                "printAlert":       "",
                "printTypeM":       printTypeMs,
                "activityUrl" :     "",
                "hotsDisplayRack":  {title:"热门展架", list: results[12]},
                "serviceTel"    : "027-87101355",
                "couponActivity"  : 0,
                "hiddenFirstActivity" : 0
            };
            return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, data,res);
        });
}
router.get('/getMainPage_v5_1', getMainPage_v5_1);
router.post('/getMainPage_v5_1', getMainPage_v5_1);


//---------------------------------------------------------------------------------
/**
 * 参数: device	"0 表示从pc来的请求  1 表示ios  2 表示android
 * 参数: uuid	 设备唯一标识
 * 参数: userId	用户唯一标识
 * 参数: typeL	请求数据的一级分类,   1. 海报, 3 ppt, 6社交媒体
 * 参数: typeM	请求数据的二级分类(-1 标示最新)
 * 参数[可选]: typeS	请求数据的三级分类, 若不存在标识仅以一级二级分类请求数据
 * 参数: pageNum	请求指定页页码
 * 参数: pageSize	请求指定页大小
 * 返回：
 *    {
 *        "success":1,
 *        "msg":"成功",
 *        "data":{
 *            "list":[
 *                {
 *                    "id":387,
 *                    "thumb":"http:\/\/itbour-generate.oss-cn-hangzhou.aliyuncs.com\/image\/U12\/2017\/01\/12\/104159707_98ej3GaNqJhaoFzcd0iB\/0.jpg",
 *                    "title":"商务办公海报特惠",
 *                    "desc":"1.90 元",
 *                    "typeL":4,
 *                    "w":1600,
 *                    "h":900
 *                }
 *            ],
 *            "colmun":2
 *        }
 *    }
 *
 * 测试地址: http://localhost:3000/v5/tg3/getEquivalentTypeList_v5_1?typeL=1&pageNum=0&pageSize=12
 */
// 对应老接口: /tg3/getEquivalentTypeList
function getEquivalentTypeList_v5_1(req, res, next) {
    // get parameters
    var device = req.query.device || req.body.device;
    var uuid = req.query.uuid || req.body.uuid;
    var userId = req.userId || req.body.userId;
    var typeL = Number(req.query.typeL || req.body.typeL || 0);
    var typeM = Number(req.query.typeM || req.body.typeM || 0);
    var typeS = Number(req.query.typeS || req.body.typeS || 0);
    var pageNum = Number(req.query.pageNum || req.body.pageNum || 0);
    var pageSize = Number(req.query.pageSize || req.body.pageSize || 0);

    // check parameters
    if(typeof typeL == 'undefined' || isNaN(typeL) || typeL == null || typeL == 0) {
        return tg3Util.ret_func_json(0,'大分类未指定',{},res);
    }
    if (typeof typeM=='undefined' || isNaN(typeM) || typeM==null) {
        return tg3Util.ret_func_json(0,'中分类未指定',{},res);
    }

    tg3Util.getEquivalentTypeList(typeL,typeM,typeS,pageNum,pageSize,function(err,retData){
        if(err){
            console.log(err);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }
        var column = tg3Util.getAppShowColumn(typeL, typeM, typeS);

        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS,{list:retData || [], column:column},res);
    });
}
router.get('/getEquivalentTypeList_v5_1', getEquivalentTypeList_v5_1);
router.post('/getEquivalentTypeList_v5_1', getEquivalentTypeList_v5_1);

//---------------------------------------------------------------------------------
/**
 * 获取设计列表数据
 * 参数: device   0 表示从pc来的请求  1 表示ios  2 表示android
 * 参数: uuid     设备唯一标识
 * 参数: userId   用户唯一标识
 * 参数: typeL    请求数据的一级分类,   1 海报, 3 ppt, 6 社交媒体, 7 电商, 8 微商
 * 参数: typeM    请求数据的二级分类(-1 标示最新)
 * 参数[可选]: typeS 请求数据的三级分类, 若不存在标识仅以一级二级分类请求数据
 * 参数: pageNum  请求指定页页码
 * 参数: pageSize 请求指定页大小
 * 返回：
 *    {
 *        "success":1,
 *        "msg":"成功",
 *        "data":{
 *            "list":[
 *                {
 *                    "id":387,
 *                    "thumb":"http:\/\/itbour-generate.oss-cn-hangzhou.aliyuncs.com\/image\/U12\/2017\/01\/12\/104159707_98ej3GaNqJhaoFzcd0iB\/0.jpg",
 *                    "title":"商务办公海报特惠",
 *                    "desc":"1.90 元",
 *                    "typeL":4,
 *                    "w":1600,
 *                    "h":900,
 *                    "useCounts":123,
 *                    "vip": 10,// 新增 vip 标记字段, 0 标识普通模板, 10 标识 vip 模板
 *                }
 *            ],
 *            "colmun":2
 *        }
 *    }
 *
 * 对应老接口: /v5/tg3/getEquivalentTypeList_v5_1
 */
function getEquivalentTypeList_v6_0(req, res, next) {
    // get parameters
    var device = req.query.device || req.body.device;
    var uuid = req.query.uuid || req.body.uuid;
    var userId = req.userId || req.body.userId;
    var typeL = Number(req.query.typeL || req.body.typeL || 0);
    var typeM = Number(req.query.typeM || req.body.typeM || 0);
    var typeS = Number(req.query.typeS || req.body.typeS || 0);
    var pageNum = Number(req.query.pageNum || req.body.pageNum || 0);
    var pageSize = Number(req.query.pageSize || req.body.pageSize || 0);

    // check parameters
    if(typeof typeL == 'undefined' || isNaN(typeL) || typeL == null || typeL == 0) {
        return tg3Util.ret_func_json(0,'大分类未指定',{},res);
    }
    if (typeof typeM=='undefined' || isNaN(typeM) || typeM==null) {
        return tg3Util.ret_func_json(0,'中分类未指定',{},res);
    }

    tg3Util.getEquivalentTypeList_v6_0(typeL,typeM,typeS,pageNum,pageSize,function(err,retData){
        if(err){
            console.log(err);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }
        var column = tg3Util.getAppShowColumn(typeL, typeM, typeS);

        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS,{list:retData || [], column:column},res);
    });
}
router.get('/getEquivalentTypeList_v6_0', getEquivalentTypeList_v6_0);
router.post('/getEquivalentTypeList_v6_0', getEquivalentTypeList_v6_0);


//---------------------------------------------------------------------------------
/**
 * 参数: device	"0 表示从pc来的请求
 * 1 表示ios
 * 2 表示android
 * 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 3  标示app 嵌入网页"
 * 参数: uuid  设备唯一标识
 * 参数: userId  用户唯一标识
 * 参数: keyword  关键词(去特殊字符, 以 空格分割, 以 半角 , 拼接)
 * 参数: typeLs  搜索分类,  0 未分类, 1 海报, 2 多页, 3 ppt, 4 印品 的数组的 json 字符串 如: “[1,3]”
 * 参数: pageNum  搜索结果对应页
 * 参数: pageSize  搜索结果请求页大小
 * 测试地址: http://localhost:3000/v5/tg3/search_v5_1?keyword=%E9%BB%84&typeLs=[1,3,4]&withTotalPage=1
 * */
// 对应老接口: /tg3/search
// todo 修改接口, 已完成, 待审核 begin
function search_v5_1(req, res, next) {

    //var typeLs = JSON.parse(req.query.typeLs || req.body.typeLs || '[]');
    //
    //var data = {"result":[{"thumb":"http://xxx.jpg","id":788,"typeL":1,"name":"快递开业通知模板","desc":"海报","author":"by乌头马角工作室","time":"2016-12-05 13:38"}]};
    //return ret_func(1, CODE.OPERATION_SUCCESS, data, res);

    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = req.body.userId || req.query.userId;
    var keyword = req.body.keyword || req.query.keyword || '';
    var typeLs = req.body.typeLs || req.query.typeLs || '[]';
    var pageNum = Number(req.body.pageNum || req.query.pageNum || '0');
    var pageSize = Number(req.body.pageSize || req.query.pageSize || '12');
    var withTotalPage = Number(req.body.withTotalPage || req.query.withTotalPage || '0');

    if(!keyword || keyword.length==0){
        return tg3Util.ret_func_json(0,CODE.SERACH_KEYWORD_EMPTY,{},res);
    }
    if(keyword.length>10){
        //return tg3Util.ret_func_json(0,CODE.SERACH_KEYWORD_TOO_LONG,{},res);
    }

    tg3Util.get_search_v5_1(keyword, typeLs, pageNum, pageSize, function (error, data) {
        if (error) {
            console.log('v5/tg3.js search Err: '+error);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }

        var ret = {"result":data, currentPage:pageNum};
        // 不需要总页数
        if(!withTotalPage) {
            return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, ret, res);
        }

        // 需要总页数
        tg3Util.get_search_v5_1_Cnt(keyword, typeLs, function(error1, count){
            if (error1) {
                console.log('v5/tg3.js search Err: '+error1);
                return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
            }
            ret.totalPage = Math.floor((count-1)/pageSize)+1;
            return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, ret, res);
        });
    });
}
router.get('/search_v5_1', search_v5_1);
router.post('/search_v5_1', search_v5_1);
// todo 修改接口, 已完成, 待审核 end
//---------------------------------------------------------------------------------
/**
 * 获取快速创建信息接口
 * 参数: device	请求来源
 * 参数: uuid	设备唯一标识
 * 参数: userId	用户唯一标识
 * */
// 对应老接口: /tg3/getTagByTypeL
function getTagByTypeL_v5_1(req, res, next) {

    //var data = {"result":[{"id":1,"name":"设计","sub":[{"id":10100,"name":"邀请函","sub":[{"id":40101,"name":"开业庆典"},{"id":40102,"name":"讲座会议"}]},{"id":10200,"name":"促销海报","sub":[{"id":10201,"name":"节日促销"}]}]},{"id":4,"name":"印品","sub":[{"id":40100,"name":"名片"},{"id":40200,"name":"传单"}]}]};
    //return ret_func(1, CODE.OPERATION_SUCCESS, data, res);

    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var typeL = Number(req.body.typeL || req.query.typeL || '0');

    async.series([
        function(callback){
            tg3Util.getTagByTypeL(1, function(error,data){ callback(error,data)});//*** results[0]
        },
        function(callback){
            //tg3Util.getTagByTypeL(2, function(error,data){ callback(error,data)});//*** results[1]
            callback(null,null);
        },
        function(callback){
            //tg3Util.getTagByTypeL(3, function(error,data){ callback(error,data)});//*** results[2]
            callback(null,null);
        },
        function(callback){
            tg3Util.getTagByTypeL(4, function(error,data){ callback(error,data)});//*** results[3]
        }
    ],

    function(err, results){
        if(err){
            console.log('v5/tg3.js getTagByTypeL_v5_1 Err: '+err);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }
        // todo 接口阉割, 此处写死 begin
        var printTags = [{"id":40100,"name":"名片","icon":"","sub":[]},{"id":40200,"name":"传单","icon":"","sub":[]}];
        var data = [
            {id: 1, name: '设计', sub:results[0]},
            //{id: 2, name: '多页', sub:results[1]},
            {id: 4, name: '印品', sub:printTags}
        ];
        // todo 接口阉割, 此处写死 end
        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, {"result":data}, res);
    });

}
router.get('/getTagByTypeL_v5_1', getTagByTypeL_v5_1);
router.post('/getTagByTypeL_v5_1', getTagByTypeL_v5_1);

//---------------------------------------------------------------------------------
/**
 * 根据一级二级三级分类 id(标签), 获取条目信息
 * 参数: device
 * 参数: uuid	 设备唯一标识
 * 参数: userId	用户唯一标识
 * 参数: typeL
 * 参数: typeM
 * 参数: typeS[可选]
 * */
function getItemByTag_v5_1 (req, res, next) {
    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = req.body.userId || req.query.userId;
    var typeL = Number(req.body.typeL || req.query.typeL || '0');
    var typeM = Number(req.body.typeM || req.query.typeM || '0');
    var typeS = Number(req.body.typeS || req.query.typeS || '0');

    tg3Util.getFastOutlineByType(typeL,typeM,typeS,function (error, data) {
        if (error) {
            console.log('v5/tg3.js getItemByTag_v5_1 Err: '+error);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }

        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, data, res);
    });
}
router.get('/getItemByTag_v5_1', getItemByTag_v5_1);
router.post('/getItemByTag_v5_1', getItemByTag_v5_1);

//---------------------------------------------------------------------------------
/**
 * 确认用户是否已购买模板
 * 参数 device
 * 参数 uuid:
 * 参数 userId:
 * 参数 typeL:
 * 参数 designId: 模板 id
 * 返回值: {“success":1,"msg":"成功","data":{"designId":888,"price":1000,"paid":1,"desc":"原价10元, 折扣价9.8, 是否确认购买"}}
 */
function chkBuyTmplInfo_v5_1(req, res, next) {
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = Number(req.body.userId || req.query.userId || '0');
    var typeL = Number(req.body.typeL || req.query.typeL || '0');
    var tmplId = Number(req.body.designId || req.query.designId || '0');

    if(userId==0){
        return tg3Util.ret_func_json(0,'无效用户id',{},res);
    }
    if(typeL==0){
        return tg3Util.ret_func_json(0,'无效模版分类',{},res);
    }
    if(tmplId==0){
        return tg3Util.ret_func_json(0,'无效模版id',{},res);
    }

    tg3Util.chkBuyTmplInfo(userId, typeL, tmplId, function(error, data){
        if(error){
            console.log('v5/tg3.js [chkBuyTmplInfo_v5_1] chkInfo Err'+error);
            return tg3Util.ret_func_json(0,'error',{},res);
        }

        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, data, res);
    });
}
router.get('/chkBuyTmplInfo_v5_1', chkBuyTmplInfo_v5_1);
router.post('/chkBuyTmplInfo_v5_1', chkBuyTmplInfo_v5_1);

//---------------------------------------------------------------------------------
/**
 * 获取用户已购作品列表
 * 参数 device
 * 参数 uuid:
 * 参数 userId:
 * 参数 pageNum:
 * 参数 pageSize:
 * 返回值:
    {
        "success":1,
        "msg":"成功",
        "data":{
            "result":[
                {
                    "typeL":1,
                    "designId":888,
                    "name":"模板名称",
                    "price":1900,
                    "buyTime":"2016-12-05",// 购买时间
                    "deadline":"2017-02-24",// 有效截止日
                    "thumb":"http://oss-itbour/thumb.jpg",
                    "expired":1,// 是否过期:1过期,0未过期
                    "msg":"已过使用期"
                }
            ]
        }
    }
 */
function getBuyTmplList_v5_1(req, res, next) {
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = Number(req.body.userId || req.query.userId || '0');
    var pageNum = Number(req.body.pageNum || req.query.pageNum || '0');
    var pageSize = Number(req.body.pageSize || req.query.pageSize || '12');

    if(userId==0){
        return tg3Util.ret_func_json(0,'无效用户id',{},res);
    }

    tg3Util.getBuyTmplListByUser(userId, pageNum, pageSize, function(error, data){
        if(error){
            console.log('v5/tg3.js [getBuyTmplList_v5_1] getInfo Err'+error);
            return tg3Util.ret_func_json(0,'error',{},res);
        }

        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, {result: data}, res);
    });
}
router.get('/getBuyTmplList_v5_1', getBuyTmplList_v5_1);
router.post('/getBuyTmplList_v5_1', getBuyTmplList_v5_1);

//------------------------------------网页端 getMainPageForWeb 模拟接口---------------------------------------------
/**
 * 获取网站首页数据
 *
 * 参数: device	"0 表示从pc来的请求
 * 1 表示ios
 * 2 表示android
 * 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 3 标识app 嵌入网页
 * 4 标识网站 web 端"
 *
 * 注意: web 的轮播图 与 app 轮播图应进行区分, 建议两端轮播图进行区分, 便于 app 和 web 上不同的轮播图
 *
 * 测试地址: http://localhost:3000/v5/tg3/getMainPageForWeb_v5_2
 * */
function getMainPageForWeb_v5_2 (req, res, next) {

    var device = Number(req.query.device || req.body.device || '0');

    // 轮播图数据, 其余与 app 类似, 鉴于网页端的及时性, 返回信息不需要包裹一层了
    async.series([
            function(callback){
                tg3Util.get_adInfo_by_type(13, function(error,data){ callback(error,data)});//*** results[0] // 消息分类: 1:App普通msg; 2:App横幅banner信息；3:App轮播图; 13:Web轮播图
            },
            function(callback){
                tg3Util.get_hotsPPT(function(error,data){ callback(error,data)});//*** results[1]
            },
            function(callback){
                tg3Util.get_hotsPoster(function(error,data){ callback(error,data)});//*** results[2]
            },
            function(callback){
                tg3Util.get_hotsBusinessCard(function(error,data){ callback(error,data)});//*** results[3]
            },
            function(callback){
                tg3Util.get_hotsLeaflet(function(error,data){ callback(error,data)});//*** results[4]
            }
        ],
        function(err, results){
            if(err){
                console.log(err);
                return tg3Util.ret_func_json(0,'error',{},res);
            }
            var data = {
                "adInfo":           results[0],
                "hotsPPT":          results[1],
                "hotsPoster":       results[2],
                "hotsBusinessCard": results[3],
                "hotsLeaflet":      results[4]
            };
            return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, data,res);
        });

}
router.get('/getMainPageForWeb_v5_2', getMainPageForWeb_v5_2);
router.post('/getMainPageForWeb_v5_2', getMainPageForWeb_v5_2);


//------------------------------------网页端 getFilterListForWeb 模拟接口---------------------------------------------
/**
 * 获取模板/商品筛选列表
 * 参数: device	"0 表示从pc来的请求
 * 1 表示ios
 * 2 表示android
 * 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 3 标识app 嵌入网页
 * 4 标识网站 web 端"
 * 参数: typeL	所需一级分类的 id, 海报 1, 幻灯片 3, 印品 4
 * 参数: typeM	所需二级分类 id, -1 标示获取最新
 * 参数: [可选] colors	所需颜色分类 id 数组的 json 字符串, 鉴于网页端可随时发布, 颜色对应可直接写死, 如需多选, 将所选验证传递即可, 如: "[1, 2, 3]"
 * 参数: pageNum	请求页码, 从 0 开始
 * 参数: pageSize	请求页大小
 * 参数: [可选] tags[待定]	所需热门标签 id 数组的 json 字符串, 鉴于网页端可随时发布, 标签对应可直接写死, 如需多选, 将所选标签传递即可, 如: "[1, 2]"
 * 参数: [可选] withTotalPage 是否需要总页数
 *
 * 注意: 当前版本由于 ppt 整体不变, 所以此接口可暂时不处理 ppt
 *
 * 测试地址: http://localhost:3000/v5/tg3/getFilterListForWeb_v5_2?typeL=4&typeM=40100&colors=[]&pageSize=10&pageNum=0
 *          http://localhost:3000/v5/tg3/getFilterListForWeb_v5_2?typeL=1&typeM=10&colors=[]&pageSize=10&pageNum=0
 * */
function getFilterListForWeb_v5_2 (req, res, next) {

    var device = checkUtil.stringFromReq(req, 'device');
    var typeL = checkUtil.numberFromReq(req, 'typeL');
    if(!typeL) {
        return tg3Util.ret_func_json(0, CODE.TYPE_L_EMPTY, {}, res);
    }
    var typeM = checkUtil.numberFromReq(req, "typeM");
    var colors = checkUtil.stringFromReq(req, 'colors');
    if (colors) {
        colors = JSON.parse(colors);
    }
    var tags = checkUtil.stringFromReq(req, "tags");
    if (tags) {
        tags = JSON.parse(tags);
    }
    var withTotalPage = checkUtil.numberFromReq(req, 'withTotalPage');
    var pageNum = checkUtil.numberFromReq(req, 'pageNum') ;
    var pageSize = checkUtil.numberFromReq(req, 'pageSize') ;


    var data = null;
    // 海报
    if(typeL == 1) {
        //data = {"list":[{"id":515,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/07/153525097_fBkxBZpSet3FHB9K9CWS/0.jpg","typeL":1,"title":"大声说爱你情人节祝福模板","desc":"2.00元"},{"id":518,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/08/110253868_lU0U2IJjTsSePDGNSf2L/0.jpg","typeL":1,"title":"元宵节祝福模板","desc":"0.01元"},{"id":514,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/07/125958506_mH1vQNMs39phfHwUUJzj/0.jpg","typeL":1,"title":"星空科技风招聘会邀请函","desc":"免费"},{"id":513,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/07/124358282_p8yoDgOSgSFIT66Z8Wz4/0.jpg","typeL":1,"title":"高端黑底花卉招聘会邀请函","desc":"免费"},{"id":512,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/170619565_CcO3rScnFsxqKM0HvjqP/0.jpg","typeL":1,"title":"情人节祝福模板","desc":"免费"},{"id":511,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/162752771_evKtqh0Yhp1oecXCnJRg/0.jpg","typeL":1,"title":"情人节祝福模板","desc":"免费"},{"id":510,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/06/162506654_rSxpK7gpVrI02EUz3gHB/0.jpg","typeL":1,"title":"浪漫情人节祝福模板","desc":"免费"},{"id":509,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/131828121_ai6jpQxPzYlOzHGtcWNC/0.jpg","typeL":1,"title":"闹元宵节日祝福模板","desc":"免费"},{"id":508,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/131042500_9dqHkdSHitAguANzxhW6/0.jpg","typeL":1,"title":"大灯笼喜乐元宵祝福模板","desc":"免费"},{"id":507,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/06/105747117_oUrB7CKahhJeiFx39KNL/0.jpg","typeL":1,"title":"正月十五元宵节祝福模板","desc":"免费"}],"totalPage":10, "currentPage" : 0};
        //return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);

        tg3Util.getFilterListForWebOfPoster(typeM,colors,tags, withTotalPage, pageNum, pageSize, function(error, data ){
            if(error){
                return tg3Util.ret_func_json(0, CODE.OPERATION_FAILED, {}, res);
            }
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
        });
    }
    // 印品
    else if (typeL == 4) {
        //if (typeM == 40100) {
        //    data = {"list":[{"id":56,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/125048763_VklJ7QGTZPixnRPIkewC.jpg","typeL":4,"title":"蓝色lowpoly通用名片","desc":"印刷 20.00元/2盒"},{"id":52,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/123755826_oA8xSnUw8ftcZyl9wGZo.jpg","typeL":4,"title":"灰金个性商务名片","desc":"印刷 20.00元/2盒"},{"id":51,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/123529924_qCMLw4bsRRcIJgyOwJxR.jpg","typeL":4,"title":"黑金简约商务名片","desc":"印刷 20.00元/2盒"},{"id":50,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/120812416_hlhmpfKw8gBfiSGjgorL.jpg","typeL":4,"title":"红色商务简约名片","desc":"印刷 20.00元/2盒"},{"id":42,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/110525602_qpYgK16iivXvC3tW0e2u.jpg","typeL":4,"title":"蓝红通用商务名片","desc":"印刷 20.00元/2盒"},{"id":36,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/102942370_9Bx9pcQXKTmh4P5gB0de.jpg","typeL":4,"title":"黑白商务简约名片","desc":"印刷 20.00元/2盒"},{"id":35,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/102650265_mtYWn4840q8VterDhuty.jpg","typeL":4,"title":"黄色个性商务名片","desc":"印刷 20.00元/2盒"},{"id":32,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/101316667_zXNfcAuLIZZ6zdhnzRi6.jpg","typeL":4,"title":"黑白简约通用名片","desc":"印刷 20.00元/2盒"},{"id":30,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/095739604_LKOcPzEMrBHxLJn6bwzu.jpg","typeL":4,"title":"灰绿简约商务名片","desc":"印刷 20.00元/2盒"},{"id":29,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/095555782_sBKduzplJRkgFbe0GlIg.jpg","typeL":4,"title":"黑白简约商务名片","desc":"印刷 20.00元/2盒"}],"totalPage":10, "currentPage" : pageNum};
        //} else {
        //    data = {"list":[{"id":74,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/21/101650910_hmeIddRiOvyKigqGGsao.jpg","typeL":4,"title":"灰白简约企业宣传单","desc":"印刷 174.00元/500张"},{"id":71,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/165111597_zFMEqwXCnt4XjLLSf3Yi.jpg","typeL":4,"title":"黄色通用企业宣传单","desc":"印刷 174.00元/500张"},{"id":70,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/164935937_AR1pskirDugOxdXGHqb4.jpg","typeL":4,"title":"红色通用企业宣传单","desc":"印刷 174.00元/500张"},{"id":69,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/164638068_wg7aOB15d4o5ia3LRjeM.jpg","typeL":4,"title":"蓝色科技风企业宣传单","desc":"印刷 174.00元/500张"},{"id":67,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144906941_9sH0bSBTAGNHtaOBciwG.jpg","typeL":4,"title":"蓝色商务企业宣传单","desc":"印刷 174.00元/500张"},{"id":66,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144747327_4168yO09UforziBMRyaP.jpg","typeL":4,"title":"黑白简约企业宣传单","desc":"印刷 174.00元/500张"},{"id":65,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144603542_Tc4w3IrCmhOSkR3DEVkD.jpg","typeL":4,"title":"蓝色商务企业宣传单","desc":"印刷 174.00元/500张"},{"id":64,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/161615559_L5L3lMGEWcx5mMRStP2u.jpg","typeL":4,"title":"黄色简约企业宣传单","desc":"印刷 174.00元/500张"},{"id":63,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/161457505_hTaLF1nV37HRmYV7uHVW.jpg","typeL":4,"title":"绿色lowpoly风格企业宣传单","desc":"印刷 174.00元/500张"},{"id":26,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/175519270_m3V0rZ3UAXFLPAQEGN5R.jpg","typeL":4,"title":"绿色简约通用企业宣传单","desc":"印刷 174.00元/500张"}],"totalPage":10, "currentPage" : pageNum};
        //}
        tg3Util.getFilterListForWebOfPrint(typeM,colors,tags, withTotalPage, pageNum, pageSize, function(error, data ){
            if(error){
                return tg3Util.ret_func_json(0, CODE.OPERATION_FAILED, {}, res);
            }
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
        });

    }
    else{
        return tg3Util.ret_func_json(0, CODE.TYPE_L_ERROR, {}, res);
    }
}
router.get('/getFilterListForWeb_v5_2', getFilterListForWeb_v5_2);
router.post('/getFilterListForWeb_v5_2', getFilterListForWeb_v5_2);

//------------------------------------------- APP 端 getHotsSearch_v5_2 模拟接口 --------------------------------
/**
 * 参数:device	"0 表示从pc来的请求
 * 1 表示ios
 * 2 表示android
 * 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 3 标识app 嵌入网页
 * 4 标识网站 web 端"
 * 参数: uuid	 设备唯一标识
 * 参数[可选]: userId	用户唯一标识
 * 参数: typeLs	一级分类数组的 json 字符串
 * 返回结果	{"success":1,"msg":"成功","data":{"hotsSearch":["小清新","简约"]}}
 *
 * 测试连接: http://localhost:3000/v5/tg3/getHotsSearch_v5_2?typeLs=[1,2,3,4]
 * */
// todo 模拟接口, 待实现, begin
function getHotsSearch_v5_2 (req, res, next) {
    var typeLs = checkUtil.stringFromReq(req, 'typeLs');
    if(!typeLs) {
        return tg3Util.ret_func_json(0, 'typeLs 错误', {}, res);
    }
    typeLs = JSON.parse(typeLs);
    if(typeLs.length == 0) {
        typeLs = [1, 2, 3, 4];
    }
    tg3Util.get_hotsSearch_v5_2(typeLs, function(error, items){
        if(error) {
            console.log('/v5/tg3.js [get_hotsSearch_v5_2] err: ' + error);
            return tg3Util.ret_func_json(0, '查询失败', {}, res);
        }
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, {'hotsSearch' : items}, res);
    });
}
router.get('/getHotsSearch_v5_2', getHotsSearch_v5_2);
router.post('/getHotsSearch_v5_2', getHotsSearch_v5_2);
// todo 模拟接口, 待实现, end

// v5.2 首页接口
function getMainPage_v5_2(req, res, next) {
    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var typeL = Number(req.body.typeL || req.query.typeL || '1');

    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v5_2";
    var para = {
        device: device  // 每种来源记录一份缓存
    };
    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content){
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)});//*** results[1]
                },
                function(callback){
                    //tg3Util.get_hotsProject(function(error,data){ callback(error,data)});//*** results[2]
                    callback(null,null);
                },
                function(callback){
                    tg3Util.get_hotsPPT(function(error,data){ callback(error,data)});//*** results[3]
                },
                function(callback){
                    tg3Util.get_hotsPoster(function(error,data){ callback(error,data)});//*** results[4]
                },
                function(callback){
                    tg3Util.get_hotsMultiPage(function(error,data){ callback(error,data)});//*** results[5]
                },
                function(callback){
                    tg3Util.get_hotsBusinessCard(function(error,data){ callback(error,data)});//*** results[6]
                },
                function(callback){
                    tg3Util.get_hotsLeaflet(function(error,data){ callback(error,data)});//*** results[7]
                },
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[8]
                },
                function(callback){
                    tg3Util.get_multiPageTypeM(function(error,data){ callback(error,data)});//*** results[9]
                },
                function(callback){
                    tg3Util.get_bottomInfo(function(error,data){ callback(error,data)});//*** results[10]
                },
                function (callback) {
                    tg3Util.get_printTypeM_v5_2(function(error, data){callback(error,data)});//*** results[11]
                },
                function (callback) {
                    tg3Util.get_hotsDisplayRack_v5(function(error, data){callback(error,data)});//*** results[12]
                },
                function (callback) {
                    tg3Util.get_fastCreateTypeLAndTypeMs_v5_2(function(error,data){callback(error,data)}); //*** results[13]
                }

            ],

            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    "hotsSearch":       results[0].length>0?results[0][0]:'',
                    "adInfo":           results[1],
                    //"hotsProject":      {title:"热门专题", list:results[2]},
                    "hotsPPT":          {title:"热门幻灯片", list:results[3]},
                    "hotsPoster":       {title:"热门海报", list:results[4]},
                    "hotsMultiPage":    {title:"热门多页", list:results[5]},
                    "hotsBusinessCard": {title:"热门名片", list:results[6]},
                    "hotsLeaflet":      {title:"热门传单", list:results[7]},
                    "poseterTypeM":     results[8],
                    "multiPageTypeM":   results[9],
                    "bottomInfo":       results[10],
                    "printAlert":       "",
                    "printTypeM":       results[11],
                    "activityUrl" :     "",
                    "hotsDisplayRack":  {title:"热门展架", list: results[12]},
                    "serviceTel"    : "027-87101355",
                    "couponActivity"  : 0,
                    "hiddenFirstActivity" : 0,
                    "fastCreateTags" : results[13]
                };
                var content = StaticizeUtil.recordByRedis(__filename, uri, para,data);  // 缓存
                return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, content,res);
            });
    });

}
router.get('/getMainPage_v5_2', getMainPage_v5_2);
router.post('/getMainPage_v5_2', getMainPage_v5_2);

/**
 * 参数: device	"0 表示从pc来的请求
 * 1 表示ios
 * 2 表示android
 * 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 3  标示app 嵌入网页"
 * 参数: uuid  设备唯一标识
 * 参数: userId  用户唯一标识
 * 参数: keyword  关键词(去特殊字符, 以 空格分割, 以 半角 , 拼接)
 * 参数: typeLs  搜索分类,  1 海报, 2 多页, 3 ppt, 4 印品，6 社交媒体，7 电商，8 微商 的数组的 json 字符串 如: “[1,3]”
 * 参数: pageNum  搜索结果对应页
 * 参数: pageSize  搜索结果请求页大小
 * 参数: clientVer 客户端版本号
 * 测试地址: http://localhost:3000/v5/tg3/search_v5_2?keyword=%E9%BB%84,%E5%90%8D%E7%89%87&typeLs=[1,3,4,6,7,8]&withTotalPage=1&clientVer=6.0&pageNum=0&pageSize=20
 * */
// 对应老接口: /tg3/search
// todo 修改接口, 已完成, 待审核 begin
function search_v5_2(req, res, next) {
    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = req.body.userId || req.query.userId;
    var keyword = req.body.keyword || req.query.keyword || '';
    var typeLs = req.body.typeLs || req.query.typeLs || '[]';
    var pageNum = Number(req.body.pageNum || req.query.pageNum || '0');
    var pageSize = Number(req.body.pageSize || req.query.pageSize || '12');
    var withTotalPage = Number(req.body.withTotalPage || req.query.withTotalPage || '0');
    var clientVer = req.query.clientVer || req.body.clientVer || '';

    //if(!keyword || keyword.length==0){
    //    return tg3Util.ret_func_json(0,CODE.SERACH_KEYWORD_EMPTY,{},res);
    //}
    if(keyword.length>10){
        //return tg3Util.ret_func_json(0,CODE.SERACH_KEYWORD_TOO_LONG,{},res);
    }

    if(!clientVer || clientVer.length == 0) {
        return tg3Util.ret_func_json(0,'版本号为空',{},res);
    }

    tg3Util.get_search_v5_3(clientVer, withTotalPage, keyword, typeLs, pageNum, pageSize, function(error, data){

        if (error) {
            console.log('v5/tg3.js search Err: '+error);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }
        var ret = {"result":data, currentPage:pageNum};
        //if(withTotalPage) {
        //    if(data && data.length > 0) {
        //        data.totalPage = data[0][0].f_result;
        //    } else {
        //        data.totalPage = 0
        //    }
        //}
        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, ret, res);
    });

    //tg3Util.get_search_v5_2(keyword, typeLs, pageNum, pageSize, function (error, data) {
    //    if (error) {
    //        console.log('v5/tg3.js search Err: '+error);
    //        return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
    //    }
    //
    //    var ret = {"result":data, currentPage:pageNum};
    //    // 不需要总页数
    //    if(!withTotalPage) {
    //        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, ret, res);
    //    }
    //
    //    // 需要总页数
    //    tg3Util.get_search_v5_2_Cnt(keyword, typeLs, function(error1, count){
    //        if (error1) {
    //            console.log('v5/tg3.js search Err: '+error1);
    //            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
    //        }
    //        ret.totalPage = Math.floor((count-1)/pageSize)+1;
    //        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, ret, res);
    //    });
    //
    //});

}
router.get('/search_v5_2', search_v5_2);
router.post('/search_v5_2', search_v5_2);
// todo 修改接口, 已完成, 待审核 end

//------------------------------------------- APP 端 v5_3 相关接口 --------------------------------
/**获取模板/作品提纲微调信息
 * 参数:device	0表示从p0 表示从pc来的请求
 *              1 标识一键生成iOS端
 *              2 标识一键生成android端
 *              3  标识一键生成 app 嵌入网页
 *              4 标识一键生成 web 端
 *              5 标识一键生成微信端
 *              101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 *              201 标识利楚商务
 *              301 标识酒单网
 * 参数: isDesign	是否为设计标记
 * 参数: typeL	0 未分类   1 海报  2 多页  3 ppt. 4, 印品, 6, 社交媒体
 * 参数: docId	 对应文档 id, 可能是模板 id 也可能是用户文档 id, 根据 tmplFlg 区分
 * 参数: userId	用户唯一标识
 * 返回结果:
 *          {
 *               "success": 1,
 *               "msg": "成功",
 *               "data": {
 *                 "bleedHeight": 36,
 *                 "bleedWidth": 36,
 *                 "coreStructure": {},            // 文档核心结构对象
 *                 "designId": 738,
 *                 "designNm": "红色线型简约名片",
 *                 "pageCount": 2,
 *                 "pageHeight": 709,
 *                 "pageWidth": 1134,
 *                 "productId": 0,
 *                 "productNm": "",
 *                 "textObjects": “",               //  微调初始化字符串
 *                 "typeL": 4
 *               }
 *            }
 *
 * 测试地址: http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3?isDesign=1&typeL=1&&docId=582&userId=13 // vip 模板 非 vip 用户
 *          http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3?isDesign=1&typeL=1&&docId=582&userId=299188 // vip 模板, vip 用户
 *          http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3?isDesign=1&typeL=1&&docId=520&userId=13 // 非 vip 模板, 非 vip 用户
 *          http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3?isDesign=0&typeL=1&&docId=528&userId=13
 * */
function getTgAndFineTuneInfo_v5_3 (req, res, next) {
    var device = checkUtil.stringFromReq(req, 'device');
    var isDesign = checkUtil.numberFromReq(req, 'isDesign');
    var typeL = checkUtil.numberFromReq(req, 'typeL');
    if(!typeL) {
        return tg3Util.ret_func_json(0, CODE.TYPE_L_EMPTY, {}, res);
    }
    if(typeL==2 || typeL==3) {
        return tg3Util.ret_func_json(0, CODE.TYPE_L_NOT_SUPPORT, {}, res);
    }
    var docId = checkUtil.numberFromReq(req, 'docId');
    if(!docId) {
        return tg3Util.ret_func_json(0, CODE.DOC_ID_EMPTY, {}, res);
    }
    var userId = checkUtil.numberFromReq(req, 'userId');
    if(!userId) {
        return tg3Util.ret_func_json(0, CODE.USER_ID_EMPTY, {}, res);
    }

    tg3Util.getTgAndFineTuneInfo_v5_3(isDesign, typeL,docId, userId,  function(error, data){
        if(error || !data || !data.coreStructure) {
            console.log('/v5/tg3.js [getTgAndFineTuneInfo_v5_3] err: ' + error);
            var errMsg = typeof error == 'string' ? error : CODE.OPERATION_FAILED;
            return tg3Util.ret_func_json(0, errMsg, {}, res);
        }
        // 将data中的coreStructure转换为对象
        data.coreStructure = data.coreStructure
            .replace(/\n/g,'\\n').replace(/\t/g,'').replace(/\r/g,'') //.replace(/\\"/g,'\\\\\\"')
            .replace(/[\x00-\x09\x0B-\x1F\x7F-\x9F]/g, "");
        data.coreStructure = JSON.parse(data.coreStructure);

        // add by wangjun 2018-05-31 增加推荐区域偏移
        data.optionOffsetWidth = data.bleedWidth * CONFIG.YJSC_EDITABLE_MULTIPLE_BLEED || 0;
        data.optionOffsetHeight = data.bleedHeight * CONFIG.YJSC_EDITABLE_MULTIPLE_BLEED || 0;

        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
    });
}
router.get('/getTgAndFineTuneInfo_v5_3', getTgAndFineTuneInfo_v5_3);
router.post('/getTgAndFineTuneInfo_v5_3', getTgAndFineTuneInfo_v5_3);


//------------------------------------------- APP 端 v5_3 相关接口 --------------------------------
/**保存提纲微调信息
 * 参数:device	0表示从p0 表示从pc来的请求
 *              1 标识一键生成iOS端
 *              2 标识一键生成android端
 *              3  标识一键生成 app 嵌入网页
 *              4 标识一键生成 web 端
 *              5 标识一键生成微信端
 *              101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 *              201 标识利楚商务
 *              301 标识酒单网
 * 参数: userId	用户唯一标识
 * 参数: doc	对应提纲微调信息 json 字符串
 *              "{
 *                  "coreStructure": {},            // 文档核心结构对象
 *                  "designId": 738,                // 更新时不需要传递, 新建时需要
 *                  "productId": 0,                  // 为0 标识模板, 保存时新建, 不为零时标识作品, 保存时仅更新
 *                  "productNm": "",
 *                  "textObjects": “",               //  微调初始化字符串
 *                  “tag” : [1]                          // 提纲特征值
 *              }"
 * 参数[可选]: clrHis	是否删除切换模版历史记录(等于1时删除,默认不删除)
 * 参数: typeL	0 未分类   1 海报  2 多页  3 ppt. 4, 印品, 6, 社交媒体
 * 返回结果:	{
 *              "success": 1,
 *              "message": "成功",
 *              "data":
 *                  {
 *                      "productId": 12345
 *                  }
 *          }
 * */
function saveTgAndFineTuneInfo_v5_3 (req, res, next) {
    var device = checkUtil.stringFromReq(req, 'device');
    var userId = checkUtil.numberFromReq(req, 'userId');
    if(!userId) {
        return tg3Util.ret_func_json(0, CODE.USER_ID_EMPTY, {}, res);
    }
    var doc = checkUtil.stringFromReq(req, 'doc');
    if(!doc || doc.length==0){
        return tg3Util.ret_func_json(0, CODE.DOC_DATA_EMPTY, {}, res);
    }
    doc = JSON.parse(doc); // 转换成JSON对象
    var clrHis = checkUtil.numberFromReq(req, 'clrHis');
    if(CONFIG.DEBUG==1)    clrHis = 0;
    var typeL = checkUtil.numberFromReq(req, 'typeL');
    if(!typeL) {
        return tg3Util.ret_func_json(0, CODE.TYPE_L_EMPTY, {}, res);
    }
    if(typeL==2 || typeL==3) {
        return tg3Util.ret_func_json(0, CODE.TYPE_L_NOT_SUPPORT, {}, res);
    }

    tg3Util.saveTgAndFineTuneInfo_v5_3(userId, doc, clrHis, typeL, 0,function(error, data){
        if(error) {
            console.log('/v5/tg3.js [saveTgAndFineTuneInfo_v5_3] err: ' + error);
            return tg3Util.ret_func_json(0, CODE.OPERATION_FAILED, {}, res);
        }
        // 将data中的coreStructure转换为对象
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
    });

}
router.get('/saveTgAndFineTuneInfo_v5_3', saveTgAndFineTuneInfo_v5_3);
router.post('/saveTgAndFineTuneInfo_v5_3', saveTgAndFineTuneInfo_v5_3);


//------------------------------------------- APP 端 v5_3 相关接口 --------------------------------
/** 获取微调可使用字体列表
 * 参数:device	0表示从p0 表示从pc来的请求
 *              1 标识一键生成iOS端
 *              2 标识一键生成android端
 *              3  标识一键生成 app 嵌入网页
 *              4 标识一键生成 web 端
 *              5 标识一键生成微信端
 *              101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 *              201 标识利楚商务
 *              301 标识酒单网
 * 参数: userId	用户唯一标识
 * 返回结果:	{
 *              "success": 1,
 *              "message": "成功",
 *              "data":
 *                  {
 *                      "fonts": [{"font":"字体名","thumb":"xxxxx.png"}]
 *                  }
 *          }
 * */
function getFineTuneFontList (req, res, next) {
    var device = checkUtil.stringFromReq(req, 'device');
    var userId = checkUtil.numberFromReq(req, 'userId');
    if(!userId) {
        return tg3Util.ret_func_json(0, CODE.USER_ID_EMPTY, {}, res);
    }

    tg3Util.getDefaultFinetuneFonts(function(error, data){
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, {fonts:data}, res);
    });

}
router.get('/getFineTuneFontList', getFineTuneFontList);
router.post('/getFineTuneFontList', getFineTuneFontList);

//------------------------------------------- APP 端 v5_3 相关接口 --------------------------------
/** 获取自动回复消息列表
 * 参数:device	0表示从p0 表示从pc来的请求
 *              1 标识一键生成iOS端
 *              2 标识一键生成android端
 *              3  标识一键生成 app 嵌入网页
 *              4 标识一键生成 web 端
 *              5 标识一键生成微信端
 *              101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 *              201 标识利楚商务
 *              301 标识酒单网
 * 参数: version	指定消息版本
 * 返回结果:
 *  {
 *     "data": {
 *       "qa": [
 *         {
 *           "id": 1,
 *           "keyword": “订单,下单,发货",
 *           "typeDesc": “订单相关",
 *           "qaList": [
 *             {
 *               "id": 11,
 *               "q": "下单后多久能发货?",
 *               "a": "订单下单后一般需要一天左右的时间印刷",
 *               "qEx": {
 *                 "desc": "查询物流信息",
 *                 "url": "https://www.kuaidi100.com"
 *               }
 *             }
 *           ]
 *         }
 *       ],
 *       "version": 1
 *     },
 *     "msg": "成功",
 *     "success": 1
 *  }
 * */
function getAutoRelayInfo_v5_3(req, res, next) {
    var version = checkUtil.numberFromReq(req, 'version');

    tg3Util.getAutoRelayInfo_v5_3(version, function(error, data){
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
    });
}
router.get('/getAutoRelayInfo_v5_3', getAutoRelayInfo_v5_3);
router.post('/getAutoRelayInfo_v5_3', getAutoRelayInfo_v5_3);

//------------------------------------------- APP 端 v5_3 相关接口 --------------------------------
//
/*
*   v5.3 获取首页数据
*   测试地址：
* */
function getMainPage_v5_3(req, res, next) {
    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = Number(req.body.userId || req.query.userId || '0');

    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v5_3";
    var para = {
        device: device  // 每种来源记录一份缓存
    };
    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content){
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }



        async.series([
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)});//*** results[1]
                },
                function(callback){
                    //tg3Util.get_hotsProject(function(error,data){ callback(error,data)});//*** results[2]
                    callback(null,null);
                },
                function(callback){
                    tg3Util.get_hotsPPT_v5_3(function(error,data){ callback(error,data)});//*** results[3]
                },
                function(callback){
                    tg3Util.get_hotsPoster_v5_3(function(error,data){ callback(error,data)});//*** results[4]
                },
                function(callback){
                    //tg3Util.get_hotsMultiPage(function(error,data){ callback(error,data)});//*** results[5]
                    callback(null,null);
                },
                function(callback){
                    tg3Util.get_hotsBusinessCard_v5_3(function(error,data){ callback(error,data)});//*** results[6]
                },
                function(callback){
                    tg3Util.get_hotsLeaflet_v5_3(function(error,data){ callback(error,data)});//*** results[7]
                },
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[8]
                },
                function(callback){
                    //tg3Util.get_multiPageTypeM(function(error,data){ callback(error,data)});//*** results[9]
                    callback(null,null);
                },
                function(callback){
                    tg3Util.get_bottomInfo(function(error,data){ callback(error,data)});//*** results[10]
                },
                function (callback) {
                    tg3Util.get_printTypeM_v5_2(function(error, data){callback(error,data)});//*** results[11]
                },
                function (callback) {
                    tg3Util.get_hotsDisplayRack_v5_3(function(error, data){callback(error,data)});//*** results[12]
                },
                function (callback) {
                    tg3Util.get_fastCreateTypeLAndTypeMs_v5_3(function(error,data){callback(error,data)}); //*** results[13]
                },
                function (callback) {
                    tg3Util.get_hotsWechatCoverBigPic_v5_3(function(error,data){callback(error,data)}); //*** results[14]
                },
                function (callback) {
                    tg3Util.get_hotsWechatCoverSmallPic_v5_3(function(error,data){callback(error,data)}); //*** results[15]
                },
                function (callback) {
                    tg3Util.get_hotsWeiboPic_v5_3(function(error,data){callback(error,data)}); //*** results[16]
                },
                function (callback) {
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)}); //*** results[17]
                }

            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {

                    "adInfo":                  results[1],
                    //"hotsProject":             {title:"热门专题", list:results[2]},
                    //"hotsMultiPage":           {title:"热门多页", list:results[5]},
                    //"multiPageTypeM":          results[9],
                    //"printAlert":              "",
                    "couponActivity":          0,
                    "fastCreateTags":          results[13],
                    "hiddenFirstActivity":     1,// TODO
                    "hotsWechatCoverBigPic":   results[14],// TODO check
                    "hotsWechatCoverSmallPic": results[15],// TODO check
                    "hotsWeiboPic":            results[16],// TODO check
                    "hotsBusinessCard":        results[6],
                    "hotsDisplayRack":         results[12],
                    "hotsLeaflet":             results[7],
                    "hotsPPT":                 results[3],
                    "hotsPoster":              results[4],
                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "poseterTypeM":            results[8],
                    "printTypeM":              results[11],
                    "socialMediaTypeM":        results[17] || [],// TODO check
                    "bottomInfo":              results[10],
                    "activityUrl" :            "",
                    "serviceTel":             "027-87101355",
                    "qaVersion" :              1
                };
                var content = StaticizeUtil.recordByRedis(__filename, uri, para,data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });

}
router.get('/getMainPage_v5_3', getMainPage_v5_3);
router.post('/getMainPage_v5_3', getMainPage_v5_3);



//------------------------------------------- APP 端 v5_3 相关接口 --------------------------------
/** 获取微调可使用字体列表
 * 参数:device	0表示从p0 表示从pc来的请求
 *              1 标识一键生成iOS端
 *              2 标识一键生成android端
 *              3  标识一键生成 app 嵌入网页
 *              4 标识一键生成 web 端
 *              5 标识一键生成微信端
 *              101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 *              201 标识利楚商务
 *              301 标识酒单网
 * 参数: userId	用户唯一标识
 * 参数: typeL	0 未分类   1 海报  2 多页  3 ppt 4 印品 6社交媒体
 * 参数: optionalIds	[45, 78, 99]      (条目选择界面的所有选中的 可选条目对应节点的 id 数组)
 * 参数: tgId	 条目选择获取的 tgId
 * 返回结果:	参照接口: /v5/tg3/getTgAndFineTuneInfo_v5_3
 * 测试地址：http://localhost:3000/v5/tg3/getDesignByItem_v5_3?tgId=214&optionalIds=[]&userId=13
 * */
function getDesignByItem_v5_3(req, res, next) {
    var device = checkUtil.stringFromReq(req, 'device');
    var userId = checkUtil.numberFromReq(req, 'userId');
    if(!userId) {
        return tg3Util.ret_func_json(0, CODE.USER_ID_EMPTY, {}, res);
    }
    var optionalIds = JSON.parse(checkUtil.stringFromReq(req, 'optionalIds') || '[]');
    var tgId =checkUtil.numberFromReq(req, 'tgId');
    if(tgId<=0){
        return tg3Util.ret_func_json(0,CODE.DOC_ID_INVAILD,{},res);
    }
    var typeL = Number(req.body.typeL || req.query.typeL || '0');

    // 获取题纲的数据
    tg3Util.getDesignByItem(optionalIds, tgId, 1, function(error, data){
        if (error) {
            console.log('tg3.js getDesignByItem error: '+error);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }
        if(!data){
            // 返回失败
            return tg3Util.ret_func_json(0,CODE.CANNOT_FIND_DESIGN,{},res);
        }

        // 设置typeL
        data.typeL = typeL;
        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, data, res);

    });

}
router.get('/getDesignByItem_v5_3', getDesignByItem_v5_3);
router.post('/getDesignByItem_v5_3', getDesignByItem_v5_3);


//------------------------------------------- 修正v1版本的提纲的节点的obj_id不存在的bug --------------------------------
/**获取模板/作品提纲微调信息
 * 测试地址: http://localhost:3000/v5/tg3/fixTgDataOfV1
 *          http://localhost:3000/v5/tg3/fixTgDataOfV1
 * */
function fixTgDataOfV1 (req, res, next) {
    tg3Util.fixTgDataOfV1(function(error, fixCount){
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, fixCount, res);
    });
}
router.get('/fixTgDataOfV1', fixTgDataOfV1);
router.post('/fixTgDataOfV1', fixTgDataOfV1);


//------------------------------------------- 获取首页信息接口--------------------------------
/**
 * 参数: device	"0表示从p0 表示从pc来的请求
 1 标识一键生成iOS端
 2 标识一键生成android端
 3  标识一键生成 app 嵌入网页
 4 标识一键生成 web 端
 5 标识一键生成微信端

 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 201 标识利楚商务
 301 标识酒单网"

 测试地址: http://localhost:3000/v5/tg3/getMainPage_v5_4?device=1
 * */
// 获取首页新接口
// todo 新增接口, 待实现 begin
function getMainPage_v5_4(req, res, next) {
    //var data = {"activityUrl":"","couponActivity":0,"hiddenFirstActivity":1,"qaVersion":1,"serviceTel":"027-87101355","hotsSearch":"党政","poseterTypeM":[{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821250_piyCcowbMXmxe2NrFWqX","id":-1,"name":"最新"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821710_xD9WdeVxXgFtS7rPVIcN","id":10,"name":"邀请函"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821154_OlAFri8KB21MXkSlZpRo","id":20,"name":"促销"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821455_txxl43VAeSMA7aH6nHkz","id":30,"name":"求职招聘"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821498_IMZJZZBJasYf9UpaaVu1","id":50,"name":"推广"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821606_3xlM0vDR3aIj0ie0UhvD","id":90,"name":"通知"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821368_Eg3FRyfEvgVQrEdAxpov","id":92,"name":"小程序"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/17/145821307_3csUt7vPzS64qCPS3MTy","id":80,"name":"其它"}],"printTypeM":[{"icon":"","id":40100,"name":"名片"},{"icon":"","id":40200,"name":"传单"},{"icon":"","id":40300,"name":"展架"}],"socialMediaTypeM":[{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/21/151413667_aT280OgpD1RqvsPOivyJ","id":60100,"name":"公众号首图"},{"icon":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/21/151413491_CRm6WGpMeeQ51rif2kk1","id":60200,"name":" 公众号小图"}],"adInfo":[{"id":0,"kind":1,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoopPrint.jpg","title":"轮播2","type":0,"typeL":0,"url":""},{"id":0,"kind":2,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/app/AppLoop2017.jpg","title":"轮播1","type":0,"typeL":0,"url":"https://www.itbour.com"},{"id":19,"kind":3,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U126431/2017/02/07/135057537_MoDsvbNHDmVqrZdOZPxs.jpg","title":"求职招聘","type":1,"typeL":1,"url":""},{"id":18,"kind":3,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U126431/2017/02/07/143218134_rzJH8bZDqmVUUHGPNPga.jpg","title":"产品推广","type":3,"typeL":3,"url":""},{"id":23,"kind":3,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U126431/2017/02/07/165354054_t7EznOshfIoSqGuzbY9f.jpg","title":"节日祝福","type":1,"typeL":1,"url":""},{"id":24,"kind":3,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/02/28/153530683_F8pCyev2t5r6isC1ICN6.png","title":"印品专题_TST","type":40100,"typeL":4,"url":""}],"hots":[{"column":2,"direction":1,"list":[{"desc":"免费","h":500,"id":714,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U2/2017/04/13/115337584_0vcKH6GbSiChEL8smebw/0.jpg","title":"社媒_公众号封面L","typeL":6,"w":900,"useCount":399}],"title":"热门公众号首图"},{"column":3,"direction":1,"list":[],"title":"热门公众号小图"},{"column":2,"direction":0,"list":[{"desc":"印刷 20.00元/2盒","h":204,"id":56,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/125048763_VklJ7QGTZPixnRPIkewC.jpg","title":"蓝色lowpoly通用名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":51,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/123529924_qCMLw4bsRRcIJgyOwJxR.jpg","title":"黑金简约商务名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":50,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/120812416_hlhmpfKw8gBfiSGjgorL.jpg","title":"红色商务简约名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":42,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/110525602_qpYgK16iivXvC3tW0e2u.jpg","title":"蓝红通用商务名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":36,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/102942370_9Bx9pcQXKTmh4P5gB0de.jpg","title":"黑白商务简约名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":35,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/102650265_mtYWn4840q8VterDhuty.jpg","title":"黄色个性商务名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":32,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/101316667_zXNfcAuLIZZ6zdhnzRi6.jpg","title":"黑白简约通用名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":24,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/143845126_mjhPrXmZS06sWyT8LIm6.jpg","title":"绿色lowpoly风格商务名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":23,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/143727606_yJt9jSB5BrXoMbSV5C9F.jpg","title":"黑金动感商务名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":22,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/143112908_bXrILQhf3HIlXuuruPym.jpg","title":"红色简约商务名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":21,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/142452842_PpDs0AN64G5Iw9PLlg0L.jpg","title":"LowPoly简约商务名片","typeL":4,"w":344,"useCount":399},{"desc":"印刷 20.00元/2盒","h":204,"id":19,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/13/162830897_FVWlr4AV6lnQ5mbsVBVn.jpg","title":"灰蓝色通用商务名片","typeL":4,"w":344,"useCount":399}],"title":"热门名片"},{"column":2,"direction":0,"list":[{"desc":"印刷 30.00元/1张","h":204,"id":101,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/03/28/201559854_JsVXuGchrUeq7UKb3TkO.jpg","title":"海鲜盛宴促销展架","typeL":4,"w":344,"useCount":399},{"desc":"印刷 30.00元/1张","h":204,"id":99,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/03/28/200644351_6eyZDb9XDwLQg7Qage8g.jpg","title":"美味西餐促销展架","typeL":4,"w":344,"useCount":399}],"title":"热门展架"},{"column":2,"direction":0,"list":[{"desc":"印刷 210.00元/500张","h":204,"id":74,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/21/101650910_hmeIddRiOvyKigqGGsao.jpg","title":"灰白简约企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":71,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/165111597_zFMEqwXCnt4XjLLSf3Yi.jpg","title":"黄色通用企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":70,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/164935937_AR1pskirDugOxdXGHqb4.jpg","title":"红色通用企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":69,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/164638068_wg7aOB15d4o5ia3LRjeM.jpg","title":"蓝色科技风企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":67,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144906941_9sH0bSBTAGNHtaOBciwG.jpg","title":"蓝色商务企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":66,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144747327_4168yO09UforziBMRyaP.jpg","title":"黑白简约企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":65,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/20/144603542_Tc4w3IrCmhOSkR3DEVkD.jpg","title":"蓝色商务企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":64,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/161615559_L5L3lMGEWcx5mMRStP2u.jpg","title":"黄色简约企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":63,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/18/161457505_hTaLF1nV37HRmYV7uHVW.jpg","title":"绿色lowpoly风格企业宣传单","typeL":4,"w":344,"useCount":399},{"desc":"印刷 210.00元/500张","h":204,"id":26,"thumb":"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/01/16/175519270_m3V0rZ3UAXFLPAQEGN5R.jpg","title":"绿色简约通用企业宣传单","typeL":4,"w":344,"useCount":399}],"title":"热门传单"},{"column":2,"direction":0,"list":[{"desc":"1.23元","h":900,"id":4002,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2016/06/08/144614043_6e0spdwFm1xnAAaik0XZ/0.jpg","title":"魔兽","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4183,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/21/170815615_4wGu6c9yKxlNmOhZDOtD/0.jpg","title":"极简清新商务通用模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4181,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/21/164054877_p5oP7XsShoxOyZlztAVD/0.jpg","title":"大图背景年终总结模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4182,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/20/120646075_V9c1PmO8uXgTtsAcf7zo/0.jpg","title":"欧美杂志风模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4179,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/21/161328292_j4fqfU2eSB86Ws47bgOI/0.jpg","title":"水绿色清新时尚模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4180,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/20/113948374_3W381dQWVvZEJycn3aDY/0.jpg","title":"森林绿杂志风模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4176,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U4/2017/01/14/161701937_fKCKtkTKUS0ztJXY5bGM/0.jpg","title":"蓝红双色年终总结模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4173,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U4/2017/01/14/160017713_qGkHfPX6P7SiSdqZkPB3/0.jpg","title":"蓝色商务年终报告模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4175,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/14/105204234_4wt3AqZNJtYTufKxLHLj/0.jpg","title":"炫彩商务通用年终总结模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4178,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/13/145117805_Un3fcdoAlNCaj4yVAu75/0.jpg","title":"彩色系时尚ppt模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4172,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U11/2017/01/13/181911226_cjXWINpToIzbj02Lk78N/0.jpg","title":"简约线条商务汇报通用模板","typeL":3,"w":1600,"useCount":399},{"desc":"免费","h":900,"id":4174,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U8/2017/01/13/180429224_zUh75rJTe0akWwJSj00x/0.jpg","title":"简约欧美风年终总结模板","typeL":3,"w":1600,"useCount":399}],"title":"热门幻灯片"},{"column":3,"direction":0,"list":[{"desc":"2.00元","h":1280,"id":515,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/07/153525097_fBkxBZpSet3FHB9K9CWS/0.jpg","title":"大声说爱你情人节祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"0.01元","h":1280,"id":518,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/08/110253868_lU0U2IJjTsSePDGNSf2L/0.jpg","title":"元宵节祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":516,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/07/175602696_qRtp4fr8dqugQbp4EYh7/0.jpg","title":"正月十五闹元宵祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":514,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/07/125958506_mH1vQNMs39phfHwUUJzj/0.jpg","title":"星空科技风招聘会邀请函","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":513,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/07/124358282_p8yoDgOSgSFIT66Z8Wz4/0.jpg","title":"高端黑底花卉招聘会邀请函","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":512,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/170619565_CcO3rScnFsxqKM0HvjqP/0.jpg","title":"情人节祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":511,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/162752771_evKtqh0Yhp1oecXCnJRg/0.jpg","title":"情人节祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":510,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/06/162506654_rSxpK7gpVrI02EUz3gHB/0.jpg","title":"浪漫情人节祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":509,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/131828121_ai6jpQxPzYlOzHGtcWNC/0.jpg","title":"闹元宵节日祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":508,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/131042500_9dqHkdSHitAguANzxhW6/0.jpg","title":"大灯笼喜乐元宵祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":507,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U3/2017/02/06/105747117_oUrB7CKahhJeiFx39KNL/0.jpg","title":"正月十五元宵节祝福模板","typeL":1,"w":720,"useCount":399},{"desc":"免费","h":1280,"id":506,"thumb":"http://itbour-generate.oss-cn-hangzhou.aliyuncs.com/image/U12/2017/02/06/014035180_OYr5eBqVzwTeiXMqU5Xo/0.jpg","title":"科技风引领未来招聘模板","typeL":1,"w":720,"useCount":399}],"title":"热门海报"}]};
    //return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);


    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = Number(req.body.userId || req.query.userId || '0');

    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v5_4";
    var para = {
        device: device  // 每种来源记录一份缓存
    };
    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content){
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)});//*** results[1]
                },
                function(callback){
                    //tg3Util.get_hotsProject(function(error,data){ callback(error,data)});//*** results[2]
                    callback(null,null);
                },
                function(callback){
                    tg3Util.get_hotsPPT_v5_3(function(error,data){ callback(error,data)});//*** results[3]
                },
                function(callback){
                    tg3Util.get_hotsPoster_v5_3(function(error,data){ callback(error,data)});//*** results[4]
                },
                function(callback){
                    //tg3Util.get_hotsMultiPage(function(error,data){ callback(error,data)});//*** results[5]
                    callback(null,null);
                },
                function(callback){
                    tg3Util.get_hotsBusinessCard_v5_3(function(error,data){ callback(error,data)});//*** results[6]
                },
                function(callback){
                    tg3Util.get_hotsLeaflet_v5_3(function(error,data){ callback(error,data)});//*** results[7]
                },
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[8]
                },
                function(callback){
                    //tg3Util.get_multiPageTypeM(function(error,data){ callback(error,data)});//*** results[9]
                    callback(null,null);
                },
                function(callback){
                    tg3Util.get_bottomInfo(function(error,data){ callback(error,data)});//*** results[10]
                },
                function (callback) {
                    tg3Util.get_printTypeM_v5_2(function(error, data){callback(error,data)});//*** results[11]
                },
                function (callback) {
                    tg3Util.get_hotsDisplayRack_v5_3(function(error, data){callback(error,data)});//*** results[12]
                },
                function (callback) {
                    tg3Util.get_fastCreateTypeLAndTypeMs_v5_3(function(error,data){callback(error,data)}); //*** results[13]
                },
                function (callback) {
                    tg3Util.get_hotsWechatCoverBigPic_v5_3(function(error,data){callback(error,data)}); //*** results[14]
                },
                function (callback) {
                    tg3Util.get_hotsWechatCoverSmallPic_v5_3(function(error,data){callback(error,data)}); //*** results[15]
                },
                function (callback) {
                    tg3Util.get_hotsWeiboPic_v5_3(function(error,data){callback(error,data)}); //*** results[16]
                },
                function (callback) {
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)}); //*** results[17]
                }

            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    "activityUrl" :            "",
                    "couponActivity":          0,
                    "hiddenFirstActivity":     0,// 1表示隐藏iOS新安装时的抽奖
                    "qaVersion" :              1,
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏
                    "serviceTel":             "027-87101355",
                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "poseterTypeM":            results[8],
                    "printTypeM":              results[11],
                    "socialMediaTypeM":        results[17] || [],// TODO check
                    "adInfo":                  results[1],
                    "hots": [
                        results[14],// hotsWechatCoverBigPic TODO check
                        results[15],// hotsWechatCoverSmallPic TODO check
                        //results[16],// hotsWeiboPic TODO check
                        results[6],// hotsBusinessCard
                        results[12],// hotsDisplayRack
                        results[7],// hotsLeaflet
                        results[3],// hotsPPT
                        results[4],// hotsPoster
                    ],
                    "fastCreateTags":          results[13],
                    "bottomInfo":              results[10],
                };
                var content = StaticizeUtil.recordByRedis(__filename, uri, para,data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v5_4', getMainPage_v5_4);
router.post('/getMainPage_v5_4', getMainPage_v5_4);
// todo 新增接口, 待实现 end

/**
 * 2-4: 获取专题列表
 * 参数: pageNum
 * 参数: pageSize
 * 返回值:
 * {
 *   "success": 1,
 *   "msg": "成功",
 *   "data": {
 *     "column": 1,
 *     "list": [
 *       {
 *         "id": 982,
 *         "thumb": "http://itbourgenerate.osscnhangzhou.aliyuncs.com/image/0.jpg",
 *         "h": 204,
 *         "w": 344
 *       }
 *     ]
 *   }
 * }
 */
function getSpecialTopics_v5_5(req, res, next) {

    var pageNum = Number(req.query.pageNum || req.body.pageNum || '0');
    var pageSize = Number(req.query.pageSize || req.body.pageSize || '12');

    tg3Util.getSpecialTopics_v5_5(pageNum, pageSize, function(error, data){
        if (error) {
            console.log('tg3.js getSpecialTopics_v5_5 Err: '+error);
            return tg3Util.ret_func_json(0,CODE.OPERATION_FAILED,{},res);
        }

        return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, {column:1, list:data}, res);
    });
}
router.get('/getSpecialTopics_v5_5', getSpecialTopics_v5_5);
router.post('/getSpecialTopics_v5_5', getSpecialTopics_v5_5);

// 5-4: 获取首页信息
// 源接口地址: /v5/tg3/getMainPage_v5_4
// 1. hots 系列增加一个 en 字段, 标记热门英文标题
// 2. 分类增加 en 字段, 标记分类英文
// 3. 增加热门专题分类
function getMainPage_v5_5(req, res, next) {
    //{"data":{"couponActivity":0,"hiddenFirstActivity":1,"hiddenPartner":1,"qaVersion":1,"serviceTel":"02787101355","hotsSearch":"交通","activityUrl":"https://www.itbour.com/activity.html","adInfo":[{"id":989,"kind":2,"thumb":"http://itbourback.osscnhangzhou.aliyuncs.com/AppLoopPrint.jpg","title":"企业推广","typeL":4,"url":""}],"specialTopic":{"column":2,"direction":0,"title":"热门专题","en":"specialTopic","icon":"http://oss-itbour-special-topic-icon.png","list":[{"id":982,"thumb":"http://itbourgenerate.osscnhangzhou.aliyuncs.com/image/0.jpg","h":204,"w":344,"title":"热门专题","typeL":4}]},"hots":[{"column":2,"direction":0,"list":[{"desc":"98元/500张起","h":204,"id":506,"thumb":"http://itbourgenerate.osscnhangzhou.aliyuncs.com/image/0.jpg","title":"商务办公幻灯片限时特惠","typeL":4,"useCount":888,"w":344}],"title":"热门名片","icon":"http://oss-itbour-hots-icon.png","en":"Business Card"}],"poseterTypeM":[{"icon":"http://itbourback.osscnhangzhou.aliyuncs.com/app/AppLoopPrint.jpg","id":10,"name":"邀请函","en":"INVITATION"}],"printTypeM":[{"id":40100,"name":"名片","en":"Business Card"}],"socialMediaTypeM:":[{"icon":"http://itbourback.osscnhangzhou.aliyuncs.com/app/AppLoopPrint.jpg","id":20,"name":"公众号封面大图","en":"Business Card"}],"pptTypeM":[{"icon":"http://itbourback.osscnhangzhou.aliyuncs.com/app/AppLoopPrint.jpg","id":20,"name":"创业路演","en":"Startup"}]},"msg":"成功","success":1}


    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = Number(req.body.userId || req.query.userId || '0');

    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v5_5";
    var para = {
        device: device  // 每种来源记录一份缓存
    };
    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content){
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)}, true);//*** results[1]
                },
                function(callback){
                    // TODO
                    tg3Util.get_hotsSpecialTopics_v5_5(function(error,data){ callback(error,data)});//*** results[2]
                },
                function(callback){ //*** results[3]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){
                        if(data) {
                            data.title="幻灯片";
                            data.en=CONFIG.CHS_EN.getEn('幻灯片',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){ //*** results[4]
                    tg3Util.get_hotsPoster_v5_3(function(error,data){
                        if(data) {
                            data.title="单页";
                            data.en=CONFIG.CHS_EN.getEn('单页',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){
                    //tg3Util.get_hotsMultiPage(function(error,data){ callback(error,data)});//*** results[5]
                    callback(null,null);
                },
                function(callback){ //*** results[6]
                    tg3Util.get_hotsBusinessCard_v5_3(function(error,data){
                        if(data) {
                            data.title="名片";
                            data.en=CONFIG.CHS_EN.getEn('名片',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){ //*** results[7]
                    tg3Util.get_hotsLeaflet_v5_3(function(error,data){
                        if(data) {
                            data.title="传单";
                            data.en=CONFIG.CHS_EN.getEn('传单',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[8]
                },
                function(callback){
                    // TODO
                    tg3Util.get_pptType_v5_5(2,function(error,data){ callback(error,data)});//*** results[9]
                },
                function(callback){
                    tg3Util.get_bottomInfo(function(error,data){ callback(error,data)});//*** results[10]
                },
                function (callback) {
                    tg3Util.get_printTypeM_v5_5(function(error, data){callback(error,data)});//*** results[11]
                },
                function (callback) { //*** results[12]
                    tg3Util.get_hotsDisplayRack_v5_3(function(error, data){
                        if(data) {
                            data.title="展架";
                            data.en=CONFIG.CHS_EN.getEn('展架',1);
                        }
                        callback(error,data);
                    });
                },
                function (callback) { //*** results[13]
                    //tg3Util.get_fastCreateTypeLAndTypeMs_v5_3(function(error,data){callback(error,data)});
                    callback(null,null);
                },
                function (callback) { //*** results[14]
                    tg3Util.get_hotsWechatCoverBigPic_v5_3(function(error,data){
                        if(data) {
                            data.title="公众号首图";
                            data.en=CONFIG.CHS_EN.getEn('公众号首图',1);
                        }
                        callback(error,data);
                    });
                },
                function (callback) { //*** results[15]
                    tg3Util.get_hotsWechatCoverSmallPic_v5_3(function(error,data){
                        if(data) {
                            data.title="公众号小图";
                            data.en=CONFIG.CHS_EN.getEn('公众号小图',1);
                        }
                        callback(error,data);
                    });
                },
                function (callback) { //*** results[16]
                    //tg3Util.get_hotsWeiboPic_v5_3(function(error,data){callback(error,data)});
                    callback(null, null);
                },
                function (callback) {
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)}); //*** results[17]
                }

            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    //"activityUrl" :            "",
                    "hiddenVoiceInput":        1, // 标记隐藏语音输入
                    "couponActivity":          0,
                    "hiddenFirstActivity":     0,// 1表示隐藏iOS新安装时的抽奖
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏
                    "qaVersion" :              1,
                    "serviceTel":             "027-87101355",
                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "poseterTypeM":            results[8],
                    "printTypeM":              results[11],
                    "socialMediaTypeM":        results[17] || [],
                    "pptTypeM":                results[9] || [],
                    "adInfo":                  results[1],
                    "specialTopic":            results[2] || [],
                    "hots": [
                        results[14],// hotsWechatCoverBigPic
                        results[15],// hotsWechatCoverSmallPic
                        //results[16],// hotsWeiboPic
                        results[6],// hotsBusinessCard
                        results[12],// hotsDisplayRack
                        results[7],// hotsLeaflet
                        results[3],// hotsPPT
                        results[4],// hotsPoster
                    ],
                    //"fastCreateTags":          results[13],
                    "bottomInfo":              results[10],
                };
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v5_5', getMainPage_v5_5);
router.post('/getMainPage_v5_5', getMainPage_v5_5);


// 5-4: 获取首页信息
// 添加: scene:{}, fastTrack:[]
function getMainPage_v5_6(req, res, next) {

    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = Number(req.body.userId || req.query.userId || '0');

    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v5_6";
    var para = {
        device: device  // 每种来源记录一份缓存
    };
    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content){
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)}, true);//*** results[1]
                },
                function(callback){
                    // TODO
                    tg3Util.get_hotsSpecialTopics_v5_5(function(error,data){ callback(error,data)});//*** results[2]
                },
                function(callback){ //*** results[3]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){
                        if(data) {
                            data.title="幻灯片";
                            data.en=CONFIG.CHS_EN.getEn('幻灯片',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){ //*** results[4]
                    tg3Util.get_hotsPoster_v5_3(function(error,data){
                        if(data) {
                            data.title="单页";
                            data.en=CONFIG.CHS_EN.getEn('单页',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){
                    //tg3Util.get_hotsMultiPage(function(error,data){ callback(error,data)});//*** results[5]
                    callback(null,null);
                },
                function(callback){ //*** results[6]
                    tg3Util.get_hotsBusinessCard_v5_3(function(error,data){
                        if(data) {
                            data.title="名片";
                            data.en=CONFIG.CHS_EN.getEn('名片',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){ //*** results[7]
                    tg3Util.get_hotsLeaflet_v5_3(function(error,data){
                        if(data) {
                            data.title="传单";
                            data.en=CONFIG.CHS_EN.getEn('传单',1);
                        }
                        callback(error,data);
                    });
                },
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[8]
                },
                function(callback){
                    // TODO
                    tg3Util.get_pptType_v5_5(2,function(error,data){ callback(error,data)});//*** results[9]
                },
                function(callback){
                    tg3Util.get_bottomInfo(function(error,data){ callback(error,data)});//*** results[10]
                },
                function (callback) {
                    tg3Util.get_printTypeM_v5_6(function(error, data){callback(error,data)});//*** results[11]
                },
                function (callback) { //*** results[12]
                    tg3Util.get_hotsDisplayRack_v5_3(function(error, data){
                        if(data) {
                            data.title="展架";
                            data.en=CONFIG.CHS_EN.getEn('展架',1);
                        }
                        callback(error,data);
                    });
                },
                function (callback) { //*** results[13]
                    //tg3Util.get_fastCreateTypeLAndTypeMs_v5_3(function(error,data){callback(error,data)});
                    callback(null,null);
                },
                function (callback) { //*** results[14]
                    tg3Util.get_hotsWechatCoverBigPic_v5_3(function(error,data){
                        if(data) {
                            data.title="公众号首图";
                            data.en=CONFIG.CHS_EN.getEn('公众号首图',1);
                        }
                        callback(error,data);
                    });
                },
                function (callback) { //*** results[15]
                    tg3Util.get_hotsWechatCoverSmallPic_v5_3(function(error,data){
                        if(data) {
                            data.title="公众号小图";
                            data.en=CONFIG.CHS_EN.getEn('公众号小图',1);
                        }
                        callback(error,data);
                    });
                },
                function (callback) { //*** results[16]
                    //tg3Util.get_hotsWeiboPic_v5_3(function(error,data){callback(error,data)});
                    callback(null, null);
                },
                function (callback) {
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)}); //*** results[17]
                },
                function (callback) {
                    tg3Util.get_sceneList_v5_6(function(error,data){callback(error,data)}); //*** results[18]
                },
                function (callback) {
                    tg3Util.get_fastTrack_v5_6(function(error,data){callback(error,data)}); //*** results[19]
                }

            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    //"activityUrl" :            "",
                    "hiddenVoiceInput":        1, // 标记隐藏语音输入
                    "couponActivity":          0,
                    "hiddenFirstActivity":     0,// 1表示隐藏iOS新安装时的抽奖
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏
                    "qaVersion" :              1,
                    "serviceTel":             "027-87101355",
                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "poseterTypeM":            results[8],
                    "printTypeM":              results[11],
                    "socialMediaTypeM":        results[17] || [],
                    "pptTypeM":                results[9] || [],
                    "adInfo":                  results[1],
                    "specialTopic":            results[2] || [],
                    "scene":                   results[18],
                    "fastTrack":               results[19] || [],
                    "hots": [
                        results[14],// hotsWechatCoverBigPic
                        results[15],// hotsWechatCoverSmallPic
                        //results[16],// hotsWeiboPic
                        results[6],// hotsBusinessCard
                        results[12],// hotsDisplayRack
                        results[7],// hotsLeaflet
                        results[3],// hotsPPT
                        results[4],// hotsPoster
                    ],
                    //"fastCreateTags":          results[13],
                    "bottomInfo":              results[10],
                };
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v5_6', getMainPage_v5_6);
router.post('/getMainPage_v5_6', getMainPage_v5_6);

/**
 * 获取文字可调颜色列表
 * @param device
 */
function getTextColors_v5_6 (req, res, next) {
    tg3Util.getTextColors_v5_6(function(err, ret){
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, {colors:ret||[]}, res);
    });
}
router.get('/getTextColors_v5_6', getTextColors_v5_6);
router.post('/getTextColors_v5_6', getTextColors_v5_6);

//------------------------------------------------------------------------------------------------------------------------
/**
 * 获取首页数据
 *
 * 增加 eBusinessTypeM:[] 电商分类
 * hots : [], 内容扩充
 * */
function getMainPage_v5_7(req, res, next) {

    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var userId = Number(req.body.userId || req.query.userId || '0');

    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v5_7";
    var para = {
        device: device  // 每种来源记录一份缓存
    };

    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content){
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                // 热门搜索词
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                // banner 图
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)}, true);//*** results[1]
                },
                // 快速入口
                function (callback) {
                    tg3Util.get_fastTrack_v5_6(function(error,data){callback(error,data)}); //*** results[2]
                },
                // 专题
                function(callback){
                    // TODO
                    tg3Util.get_hotsSpecialTopics_v5_5(function(error,data){ callback(error,data)});//*** results[3]
                },
                // 场景案例
                function (callback) {
                    tg3Util.get_sceneList_v5_6(function(error,data){callback(error,data)}); //*** results[4]
                },
                // ppt
                function(callback){ //*** results[5]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){if(data) {data.title="幻灯片";data.en=CONFIG.CHS_EN.getEn('幻灯片',1);}callback(error,data);});
                },
                // 单页
                function(callback){ //*** results[6]
                    tg3Util.get_hotsPoster_v5_3(function(error,data){if(data) {data.title="单页";data.en=CONFIG.CHS_EN.getEn('单页',1);}callback(error,data);});
                },
                // 名片
                function(callback){ //*** results[7]
                    tg3Util.get_hotsBusinessCard_v5_3(function(error,data){if(data) {data.title="名片";data.en=CONFIG.CHS_EN.getEn('名片',1);}callback(error,data);});
                },
                // 传单
                function(callback){ //*** results[8]
                    tg3Util.get_hotsLeaflet_v5_3(function(error,data){if(data) {data.title="传单";data.en=CONFIG.CHS_EN.getEn('传单',1);}callback(error,data);});
                },
                // 展架
                function (callback) { //*** results[9]
                    tg3Util.get_hotsDisplayRack_v5_3(function(error, data){if(data) {data.title="展架";data.en=CONFIG.CHS_EN.getEn('展架',1);}callback(error,data);});
                },
                // 微信首图
                function (callback) { //*** results[10]
                    tg3Util.get_hotsWechatCoverBigPic_v5_3(function(error,data){if(data) {data.title="公众号首图";data.en=CONFIG.CHS_EN.getEn('公众号首图',1);}callback(error,data);});
                },
                // 微信小图
                function (callback) { //*** results[11]
                    tg3Util.get_hotsWechatCoverSmallPic_v5_3(function(error,data){
                        if(data) {data.title="公众号小图";data.en=CONFIG.CHS_EN.getEn('公众号小图',1);}callback(error,data);});
                },
                // 单页分类
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[12]
                },
                // ppt 分类
                function(callback){
                    // TODO
                    tg3Util.get_pptType_v5_5(2,function(error,data){ callback(error,data)});//*** results[13]
                },
                // 印品分类
                function (callback) {
                    tg3Util.get_printTypeM_v5_7(function(error, data){callback(error,data)});//*** results[14]
                },
                // 社交媒体分类
                function (callback) {
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)}); //*** results[15]
                },

        //----------------------------------------------------v5.7 新增--------------------------------------------------------------------
                // 电商分类
                function (callback) { //*** results[16]
                    tg3Util.get_eBusinessTypeM_v5_7(function(error,data){callback(error,data)}); //*** results[16]
                },
                // 停车牌
                function (callback) { //*** results[17]
                    tg3Util.get_hotsStopSign_v5_7(function(error,data){callback(error, data)});
                },
                // 淘宝主图
                function (callback) { //*** results[18]
                    tg3Util.get_hotsTaobaoMainPhoto_v5_7(function(error,data){callback(error, data)});
                },
                // 淘宝banner
                function (callback) { //*** results[19]
                    tg3Util.get_hotsTaobaoBanner_v5_7(function(error,data){callback(error, data)});
                },
                // 优惠券
                function (callback) { //*** results[20]
                    tg3Util.get_hotsPrintCoupon_v5_7(function(error,data){callback(error, data)});
                },
                // 不干胶
                function (callback) { //*** results[21]
                    tg3Util.get_hotsPrintSticker_v5_7(function(error,data){callback(error, data)});
                },
                // 招贴海报
                function (callback) { //*** results[22]
                    tg3Util.get_hotsPrintPoster_v5_7(function(error,data){callback(error, data)});
                }
            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    //"activityUrl" :            "",
                    "hiddenVoiceInput":        1, // 标记隐藏语音输入
                    "couponActivity":          0,
                    "hiddenFirstActivity":     0,// 1表示隐藏iOS新安装时的抽奖
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏
                    "qaVersion" :              1,
                    "serviceTel":             "027-87101355",

                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "adInfo":                  results[1],
                    "fastTrack":               results[2] || [],
                    "specialTopic":            results[3] || [],
                    "scene":                   results[4],
                    "hots": [

                        results[17], // 停车牌
                        results[18], // 淘宝主图
                        results[19], // 淘宝 banner

                        results[6], // 单页
                        results[5], // ppt
                        results[10], // 微信首图
                        results[11], // 微信小图

                        results[7], // 名片
                        results[8], // 传单
                        results[9], // 展架
                        results[22], // 招贴海报

                        results[20], //优惠券
                        results[21], // 不干胶
                    ],
                    "poseterTypeM":            results[12],         // 海报分类
                    "pptTypeM":                results[13] || [],   // ppt 分类
                    "printTypeM":              results[14],         // 印品分类
                    "socialMediaTypeM":        results[15] || [],   // 社交媒体分类
                    "eBusinessTypeM" :         results[16],         // 电商分类
                };
                // 热门系列截断, 保持列数显示两行
                var row = 2;
                for(var i = 0; i < data.hots.length; i++) {
                    var obj = data.hots[i];
                    if(obj && obj.list) {
                        obj.list = obj.list.slice(0, Math.floor(obj.column)*row);
                    }
                }
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v5_7', getMainPage_v5_7);
router.post('/getMainPage_v5_7', getMainPage_v5_7);

/**
 * 获取首页数据
 *
 * 增加 wechatBusiness:[] 微商分类
 * hots : [], 内容扩充
 * */
function getMainPage_v6_0(req, res, next) {

    var device = req.body.device || req.query.device;
    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v6_0";
    var para = {
        device: device  // 每种来源记录一份缓存
    };

    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content && CONFIG.DEBUG != 1){ // 有缓存, 且不是本地调试, 直接返回
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                // 热门搜索词
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                // banner 图
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)}, true);//*** results[1]
                },
                // 快速入口
                function (callback) {
                    tg3Util.get_fastTrack_v6_0(function(error,data){callback(error,data)}); //*** results[2]
                },
                // 专题
                function(callback){
                    // TODO
                    tg3Util.get_hotsSpecialTopics_v5_5(function(error,data){ callback(error,data)});//*** results[3]
                },
                // 场景案例
                function (callback) {
                    tg3Util.get_sceneList_v5_6(function(error,data){callback(error,data)}); //*** results[4]
                },
                // ppt
                function(callback){ //*** results[5]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){if(data) {data.title="幻灯片";data.en=CONFIG.CHS_EN.getEn('幻灯片',1);}callback(error,data);});
                },
                // 单页
                function(callback){ //*** results[6]
                    tg3Util.get_hotsPoster_v6_0(function(error,data){callback(error,data);});
                },
                // 名片
                function(callback){ //*** results[7]
                    tg3Util.get_hotsBusinessCard_v6_0(function(error,data){if(data) {data.title="名片";data.en=CONFIG.CHS_EN.getEn('名片',1);}callback(error,data);});
                },
                // 传单
                function(callback){ //*** results[8]
                    tg3Util.get_hotsLeaflet_v6_0(function(error,data){if(data) {data.title="传单";data.en=CONFIG.CHS_EN.getEn('传单',1);}callback(error,data);});
                },
                // 展架
                function (callback) { //*** results[9]
                    tg3Util.get_hotsDisplayRack_v6_0(function(error, data){if(data) {data.title="展架";data.en=CONFIG.CHS_EN.getEn('展架',1);}callback(error,data);});
                },
                // 微信首图
                function (callback) { //*** results[10]
                    tg3Util.get_hotsWechatCoverBigPic_v6_0(function(error,data){callback(error,data);});
                },
                // 微信小图
                function (callback) { //*** results[11]
                    tg3Util.get_hotsWechatCoverSmallPic_v6_0(function(error,data){callback(error,data);});
                },
                // -------------分类--------------
                // 单页分类
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[12]
                },
                // ppt 分类
                function(callback){
                    // TODO
                    tg3Util.get_pptType_v5_5(2,function(error,data){ callback(error,data)});//*** results[13]
                },
                // 印品分类
                function (callback) {
                    tg3Util.get_printTypeM_v5_7(function(error, data){callback(error,data)});//*** results[14]
                },
                // 社交媒体分类
                function (callback) {
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)}); //*** results[15]
                },

                //----------------------------------------------------v5.7 新增--------------------------------------------------------------------
                // 电商分类
                function (callback) { //*** results[16]
                    tg3Util.get_eBusinessTypeM_v5_7(function(error,data){callback(error,data)}); //*** results[16]
                },
                // 停车牌
                function (callback) { //*** results[17]
                    tg3Util.get_hotsStopSign_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝主图
                function (callback) { //*** results[18]
                    tg3Util.get_hotsTaobaoMainPhoto_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝banner
                function (callback) { //*** results[19]
                    tg3Util.get_hotsTaobaoBanner_v6_0(function(error,data){callback(error, data)});
                },
                // 优惠券
                function (callback) { //*** results[20]
                    tg3Util.get_hotsPrintCoupon_v6_0(function(error,data){callback(error, data)});
                },
                // 不干胶
                function (callback) { //*** results[21]
                    tg3Util.get_hotsPrintSticker_v6_0(function(error,data){callback(error, data)});
                },
                // 招贴海报
                function (callback) { //*** results[22]
                    tg3Util.get_hotsPrintPoster_v6_0(function(error,data){callback(error, data)});
                },
                //----------------------------------------------------v6.0 新增--------------------------------------------------------------------
                // 微商分类
                function (callback) { //*** results[23]
                    tg3Util.get_wechatBusiness_v6_0(function(error,data){callback(error,data)}); //*** results[16]
                },
                // 微商热门
                function (callback) { //*** results[24]
                    tg3Util.get_hotsWechatBusiness_v6_0(function(error,data){callback(error, data)});
                },
            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    //"activityUrl" :            "",
                    "hiddenVoiceInput":        1, // 标记隐藏语音输入___废弃
                    "couponActivity":          0,
                    "hiddenFirstActivity":     1,// 1表示隐藏iOS新安装时的抽奖
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏___废弃
                    "qaVersion" :              1,
                    "serviceTel":             "027-87101355",

                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "adInfo":                  results[1],
                    "fastTrack":               results[2] || [],
                    "specialTopic":            results[3] || [],
                    "scene":                   results[4],
                    "hots": [

                        results[6], // 单页
                        results[5], // ppt
                        results[10], // 微信首图
                        results[11], // 微信小图
                        results[24], // 微商
                        results[18], // 淘宝主图
                        results[19], // 淘宝 banner

                        results[7], // 名片
                        results[8], // 传单
                        results[9], // 展架
                        results[22], // 招贴海报
                        results[20], //优惠券
                        results[21], // 不干胶
                        results[17], // 停车牌

                    ],
                    "poseterTypeM":            results[12],         // 海报分类
                    "pptTypeM":                results[13] || [],   // ppt 分类
                    "printTypeM":              results[14],         // 印品分类
                    "socialMediaTypeM":        results[15] || [],   // 社交媒体分类
                    "eBusinessTypeM" :         results[16],         // 电商分类
                    "wechatBusiness" :         results[23]          // 微商分类
                };

                // 热门系列截断, 保持列数显示两行
                var row = 2;
                for(var i = 0; i < data.hots.length; i++) {
                    var obj = data.hots[i];
                    if(obj && obj.list) {
                        obj.list = obj.list.slice(0, Math.floor(obj.column)*row);
                    }
                }
                data.dailyFreeCnt = 100;
                // 测试环境限制调大
                if(CONFIG.DEBUG) {
                    data.dailyFreeCnt = 1000;
                }
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v6_0', getMainPage_v6_0);
router.post('/getMainPage_v6_0', getMainPage_v6_0);


//V6_1.获取首页数据(删除专题列表,添加秒杀以及热门);
function getMainPage_v6_1(req, res, next) {
    var device = req.body.device || req.query.device;
    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v6_1";
    var para = {
        device: device  // 每种来源记录一份缓存
    };

    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content && CONFIG.DEBUG != 1){ // 有缓存, 且不是本地调试, 直接返回
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                // 热门搜索词
                function(callback){
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});//*** results[0]
                },
                // banner 图
                function(callback){
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)}, true);//*** results[1]
                },
                // 快速入口
                function (callback) {
                    tg3Util.get_fastTrack_v6_1(function(error,data){callback(error,data)}); //*** results[2]
                },
                // 秒杀
                function(callback){
                    // TODO
                    tg3Util.get_seckillInfo_v6_1(function(error,data){ callback(error,data)});//*** results[3]
                },
                // 热门专题
                function(callback){
                    // TODO
                    tg3Util.get_specialTopicInfo_v6_1(function(error,data){ callback(error,data)});//*** results[4]
                },
                // 场景案例
                function (callback) {
                    tg3Util.get_sceneList_v5_6(function(error,data){callback(error,data)}); //*** results[5]
                },
                // ppt
                function(callback){ //*** results[6]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){if(data) {data.title="幻灯片";data.en=CONFIG.CHS_EN.getEn('幻灯片',1);}callback(error,data);});
                },
                // 单页
                function(callback){ //*** results[7]
                    tg3Util.get_hotsPoster_v6_0(function(error,data){callback(error,data);});
                },
                // 名片
                function(callback){ //*** results[8]
                    tg3Util.get_hotsBusinessCard_v6_0(function(error,data){if(data) {data.title="名片";data.en=CONFIG.CHS_EN.getEn('名片',1);}callback(error,data);});
                },
                // 传单
                function(callback){ //*** results[9]
                    tg3Util.get_hotsLeaflet_v6_0(function(error,data){if(data) {data.title="传单";data.en=CONFIG.CHS_EN.getEn('传单',1);}callback(error,data);});
                },
                // 展架
                function (callback) { //*** results[10]
                    tg3Util.get_hotsDisplayRack_v6_0(function(error, data){if(data) {data.title="展架";data.en=CONFIG.CHS_EN.getEn('展架',1);}callback(error,data);});
                },
                // 微信首图
                function (callback) { //*** results[11]
                    tg3Util.get_hotsWechatCoverBigPic_v6_0(function(error,data){callback(error,data);});
                },
                // 微信小图
                function (callback) { //*** results[12]
                    tg3Util.get_hotsWechatCoverSmallPic_v6_0(function(error,data){callback(error,data);});
                },
                // -------------分类--------------
                // 单页分类
                function(callback){
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});//*** results[13]
                },
                // ppt 分类
                function(callback){
                    // TODO
                    tg3Util.get_pptType_v5_5(2,function(error,data){ callback(error,data)});//*** results[14]
                },
                // 印品分类
                function (callback) {
                    tg3Util.get_printTypeM_v5_7(function(error, data){callback(error,data)});//*** results[15]
                },
                // 社交媒体分类
                function (callback) {
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)}); //*** results[16]
                },

                //----------------------------------------------------v5.7 新增--------------------------------------------------------------------
                // 电商分类
                function (callback) { //*** results[16]
                    tg3Util.get_eBusinessTypeM_v5_7(function(error,data){callback(error,data)}); //*** results[17]
                },
                // 停车牌
                function (callback) { //*** results[18]
                    tg3Util.get_hotsStopSign_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝主图
                function (callback) { //*** results[19]
                    tg3Util.get_hotsTaobaoMainPhoto_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝banner
                function (callback) { //*** results[20]
                    tg3Util.get_hotsTaobaoBanner_v6_0(function(error,data){callback(error, data)});
                },
                // 优惠券
                function (callback) { //*** results[21]
                    tg3Util.get_hotsPrintCoupon_v6_0(function(error,data){callback(error, data)});
                },
                // 不干胶
                function (callback) { //*** results[22]
                    tg3Util.get_hotsPrintSticker_v6_0(function(error,data){callback(error, data)});
                },
                // 招贴海报
                function (callback) { //*** results[23]
                    tg3Util.get_hotsPrintPoster_v6_0(function(error,data){callback(error, data)});
                },
                //----------------------------------------------------v6.0 新增--------------------------------------------------------------------
                // 微商分类
                function (callback) { //*** results[24]
                    tg3Util.get_wechatBusiness_v6_0(function(error,data){callback(error,data)}); //*** results[16]
                },
                // 微商热门
                function (callback) { //*** results[25]
                    tg3Util.get_hotsWechatBusiness_v6_0(function(error,data){callback(error, data)});
                },
            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    //"activityUrl" :            "",
                    "hiddenVoiceInput":        1, // 标记隐藏语音输入___废弃
                    "couponActivity":          0,
                    "hiddenFirstActivity":     1,// 1表示隐藏iOS新安装时的抽奖
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏___废弃
                    "qaVersion" :              1,
                    "serviceTel":             "027-87101355",

                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "adInfo":                  results[1],
                    "fastTrack":               results[2] || [],
                    "seckill":                 results[3],
                    "specialTopic":           results[4],
                    "scene":                   results[5],
                    "hots": [

                        results[7], // 单页
                        results[6], // ppt
                        results[11], // 微信首图
                        results[12], // 微信小图
                        results[25], // 微商
                        results[19], // 淘宝主图
                        results[20], // 淘宝 banner

                        results[8], // 名片
                        results[9], // 传单
                        results[10], // 展架
                        results[23], // 招贴海报
                        results[21], //优惠券
                        results[22], // 不干胶
                        results[18], // 停车牌

                    ],
                    "poseterTypeM":            results[13],         // 海报分类
                    "pptTypeM":                results[14] || [],   // ppt 分类
                    "printTypeM":              results[15],         // 印品分类
                    "socialMediaTypeM":        results[16] || [],   // 社交媒体分类
                    "eBusinessTypeM" :         results[17],         // 电商分类
                    "wechatBusiness" :         results[24]          // 微商分类
                };

                // 热门系列截断, 保持列数显示两行
                var row = 2;
                for(var i = 0; i < data.hots.length; i++) {
                    var obj = data.hots[i];
                    if(obj && obj.list) {
                        obj.list = obj.list.slice(0, Math.floor(obj.column)*row);
                    }
                }
                data.dailyFreeCnt = 100;
                // 测试环境限制调大
                if(CONFIG.DEBUG) {
                    data.dailyFreeCnt = 1000;
                }
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v6_1', getMainPage_v6_1);
router.post('/getMainPage_v6_1', getMainPage_v6_1);


/* 获取热门设计列表
 * 方式:GET/POST
 * 参数 device:0表示从pc来的请求1表示ios/2表示android/101表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 参数 uuid: 设备标识
 * 参数[可选]: userId:用户唯一标识
 * 参数: projectId: 专题唯一标识 id
 * 参数: pageNum: 请求页
 * 参数: pageSize: 请求页大小
 * 返回:
 *{
 *    "success":0,
 *    "msg":"成功",
 *    "data":{
 *        "list":[{ "type":1, "id":123, "thumb":"http://oss-image", "name":"xxx" }] // 印品时id为商品id
 *    }
 *}
 * 测试地址：http://localhost:3000/v5/tg3/getSpecialTopicItems_v6_0?projectId=3
 * */
function getSpecialTopicItems_v6_0(req, res, next) {
    var THIS = this;
    // get parameter
    var device = req.body.device || req.query.device;
    var uuid = req.body.uuid || req.query.uuid;
    var projectId = Number(req.body.projectId || req.query.projectId || '0');
    var pageNum = Number(req.body.pageNum || req.query.pageNum || '0');
    var pageSize = Number(req.body.pageSize || req.query.pageSize || '12');

    tg3Util.getSpecialTopicItems_v6_0(projectId, pageNum, pageSize, function(error, data){
        if(error){
            console.log(error);
            return tg3Util.ret_func_json(0,'error',{},res);
        }
        tg3Util.getSpecialTopicColumn(projectId, function(error, column){
            if(error){
                console.log(error);
                return tg3Util.ret_func_json(0,'error',{},res);
            }

            return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, {"list":data, "column":column}, res);
        });
    });

}
router.get('/getSpecialTopicItems_v6_0', getSpecialTopicItems_v6_0);
router.post('/getSpecialTopicItems_v6_0', getSpecialTopicItems_v6_0);

//--------------------------- 内测专用接口 -----------------------------------------------
/**
 *
 * 测试地址: http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3_forDebug?isDesign=1&typeL=1&&docId=582&userId=13 // vip 模板 非 vip 用户
 *          http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3_forDebug?isDesign=1&typeL=1&&docId=582&userId=299188 // vip 模板, vip 用户
 *          http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3_forDebug?isDesign=1&typeL=1&&docId=520&userId=13 // 非 vip 模板, 非 vip 用户
 *          http://localhost:3000/v5/tg3/getTgAndFineTuneInfo_v5_3_forDebug?isDesign=0&typeL=1&&docId=528&userId=13
 * */
function getTgAndFineTuneInfo_v5_3_forDebug (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    var device = checkUtil.stringFromReq(req, 'device');
    var isDesign = checkUtil.numberFromReq(req, 'isDesign');
    var typeL = checkUtil.numberFromReq(req, 'typeL');
    if(!typeL) {
        return tg3Util.ret_func_json(0, CODE.TYPE_L_EMPTY, {}, res);
    }
    if(typeL==2 || typeL==3) {
        return tg3Util.ret_func_json(0, CODE.TYPE_L_NOT_SUPPORT, {}, res);
    }
    var docId = checkUtil.numberFromReq(req, 'docId');
    if(!docId) {
        return tg3Util.ret_func_json(0, CODE.DOC_ID_EMPTY, {}, res);
    }
    var userId = checkUtil.numberFromReq(req, 'userId');
    if(!userId) {
        return tg3Util.ret_func_json(0, CODE.USER_ID_EMPTY, {}, res);
    }

    tg3Util.getTgAndFineTuneInfo_v5_3_forDebug(isDesign, typeL,docId, userId,  function(error, data){
        if(error || !data || !data.coreStructure) {
            console.log('/v5/tg3.js [getTgAndFineTuneInfo_v5_3] err: ' + error||'data.coreStructure is null');
            return tg3Util.ret_func_json(0, CODE.OPERATION_FAILED, {}, res);
        }
        // 将data中的coreStructure转换为对象
        if(data.coreStructure) {
            data.coreStructure = data.coreStructure
                .replace(/\n/g,'\\n').replace(/\t/g,'').replace(/\r/g,'') //.replace(/\\"/g,'\\\\\\"')
                .replace(/[\x00-\x09\x0B-\x1F\x7F-\x9F]/g, "");
            try {
                data.coreStructure = JSON.parse(data.coreStructure);

                // add by wangjun 2018-05-31 增加推荐区域偏移
                data.optionOffsetWidth = data.bleedWidth * CONFIG.YJSC_EDITABLE_MULTIPLE_BLEED || 0;
                data.optionOffsetHeight = data.bleedHeight  * CONFIG.YJSC_EDITABLE_MULTIPLE_BLEED || 0;

            } catch (e) {
                data.coreStructure = null;
            }
        }
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
    });
}
router.get('/getTgAndFineTuneInfo_v5_3_forDebug', getTgAndFineTuneInfo_v5_3_forDebug);
router.post('/getTgAndFineTuneInfo_v5_3_forDebug', getTgAndFineTuneInfo_v5_3_forDebug);

/*
 * 获取合伙人分享模板相关信息
 * 参数: device
 参数: partnerId	 合伙人唯一标识
 参数: id	分享条目唯一标识
 参数: typeL	分享条目一级分类
 参数: kind	10 标识普通模板, 20 标识秒杀项目
 返回结果	{"success" : 1,"msg" : "成功","data" : {"itemInfo" : {"id" : 789,"thumbs" : ["http://oss-img.jpg", "http://oss-.jpg"],"typeL" : 4,"kind" : 10 // 10 标记普通分享条目, 20 标识秒杀分享条目},"column" : 3,"similarItems" : [{"id" : 790,"thumb" : "http://oss-img.jpg","typeL" : 4,“kind" : 10 // 10 标记普通分享条目, 20 标识秒杀分享条目}]}}

测试地址:
 秒杀:
 http://localhost:3000/v5/tg3/getCityPartnerShareItemInfo_v6_1?device=1&userId=1&id=1&typeL=1010&kind=20

 单页:
 http://localhost:3000/v5/tg3/getCityPartnerShareItemInfo_v6_1?device=1&userId=1&id=54&typeL=1&kind=10

 ppt
 http://localhost:3000/v5/tg3/getCityPartnerShareItemInfo_v6_1?device=1&userId=1&id=4096&typeL=3&kind=10

 商品
 http://localhost:3000/v5/tg3/getCityPartnerShareItemInfo_v6_1?device=1&userId=1&id=627&typeL=4&kind=10

 */
function getCityPartnerShareItemInfo_v6_1(req, res, next){
    //获取对应参数
    var device = req.body.device || req.query.device;
    var userId = checkUtil.numberFromReq(req,'userId') ||0;
    var id = Number(req.body.id || req.query.id || '0');
    var typeL = Number(req.body.typeL || req.query.typeL || '0');
    var kind = Number(req.body.kind || req.query.kind || '0');
    //参数判断
    if(userId == 0){
        return tg3Util.ret_func_json(0,'合伙人ID无效',{},res);
    }
    if(id == 0){
        return tg3Util.ret_func_json(0,'商品/模版id无效',{},res);
    }
    if(typeL == 0){
        return tg3Util.ret_func_json(0,'一级分类无效',{},res);
    }
    if(kind == 0){
        return tg3Util.ret_func_json(0,'是否为秒杀商品区分字段无效',{},res);
    }
    // iOS 分享链接拼接错误, 会将所有模板分/商品的类型固定为1, 暂时再此做容错处理 add 2017-08-25 by wangjun
    if(kind == 10) {
        // 确认分享条目真实类型
        tg3Util.checkRealShareItemType(id, typeL, function(err, realId, realType){
            if(err) {
                console.log("/v5/tg3.js [getCityPartnerShareItemInfo_v6_1] err: " + err);
                return tg3Util.ret_func_json(0, 'error', {}, res);
            }
            // 获取城市合伙人分享条目信息
            tg3Util.getCityPartenerShareItemInfo(userId, realId, realType, kind, function(getInfoErr, data){
                if(getInfoErr) {
                    console.log("/v5/tg3.js [getCityPartnerShareItemInfo_v6_1] err: " + err);
                    return tg3Util.ret_func_json(0, 'error', {}, res);
                }
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
            })
        });
    } else {
        // 获取分类信息(秒杀)
        tg3Util.getCityPartenerShareItemInfo(userId, id, typeL, kind, function(getInfoErr, data){
            if(getInfoErr) {
                console.log("/v5/tg3.js [getCityPartnerShareItemInfo_v6_1] err: " + getInfoErr);
                return tg3Util.ret_func_json(0, 'error', {}, res);
            }
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, data, res);
        })
    }

}

router.get('/getCityPartnerShareItemInfo_v6_1', getCityPartnerShareItemInfo_v6_1);
router.post('/getCityPartnerShareItemInfo_v6_1', getCityPartnerShareItemInfo_v6_1);

//---------------------------------------------------------------------------------------------------------
/**
 * 获取 web 首页信息
 *
 * 测试地址: http://localhost:3000/v5/tg3/getWebMainPage_v6_0?device=4
 * */
function getWebMainPage_v6_0(req, res, next) {
    var device = checkUtil.numberFromReq(req, 'device');

    var uri = "/v5/tg3/getWebMainPage_v6_0";
    var para = {
        device: device  // 每种来源记录一份缓存
    };

    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content) {
        if (content && CONFIG.DEBUG != 1) { // 有缓存, 且不是本地调试, 直接返回
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        // 轮播图数据, 其余与 app 类似, 鉴于网页端的及时性, 返回信息不需要包裹一层了
        async.series([
                // web 轮播图
                function(callback){ //*** results[0] 消息分类: 1:App普通msg; 2:App横幅banner信息；3:App轮播图; 13:Web轮播图
                    tg3Util.get_adInfo_by_type(13, function(error,data){ callback(error,data)});
                },
                // 名片
                function(callback){ //*** results[1]
                    tg3Util.get_hotsBusinessCard_v6_0(function(error,data){if(data) {data.title="名片";data.en=CONFIG.CHS_EN.getEn('名片',1);}callback(error,data);});
                },
                // 优惠券
                function (callback) { //*** results[2]
                    tg3Util.get_hotsPrintCoupon_v6_0(function(error,data){callback(error, data)});
                },
                // 停车牌
                function (callback) { //*** results[3]
                    tg3Util.get_hotsStopSign_v6_0(function(error,data){callback(error, data)});
                },
                // 微商热门
                function (callback) { //*** results[4]
                    tg3Util.get_hotsWechatBusiness_v6_0(function(error,data){callback(error, data)});
                },
                // ppt
                function(callback){ //*** results[5]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){if(data) {data.title="幻灯片";data.en=CONFIG.CHS_EN.getEn('幻灯片',1);}callback(error,data);});
                }
            ],
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }
                // 网页端限定个数为八个, 避免跨行出现, 如果小于 八个, 就返回四个, 不够四个就有几个算几个
                var max = 8;
                var min = 4;
                if(results[1] && results[1].list){ results[1].list = results[1].list.length >= max ? results[1].list.slice(0,max) : results[1].list.slice(0,min)}
                if(results[2] && results[2].list) {results[2].list = results[2].list.length >= max ? results[2].list.slice(0,max) : results[2].list.slice(0,min)}
                if(results[3] && results[3].list) {results[3].list = results[3].list.length >= max ? results[3].list.slice(0,max) : results[3].list.slice(0,min)}
                if(results[4] && results[4].list){ results[4].list = results[4].list.length >= max ? results[4].list.slice(0,max) : results[4].list.slice(0,min)}
                if(results[5] && results[5].list){ results[5].list = results[5].list.length >= max ? results[5].list.slice(0,max) : results[5].list.slice(0,min)}
                var data = {
                    "adInfo":           results[0],
                    "hotsPrint" : [results[1],results[2],results[3]],
                    "hotsDesign" : [results[4],results[5]]
                };
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1,CODE.OPERATION_SUCCESS, content,res);
            });
    });
}
router.get('/getWebMainPage_v6_0', getWebMainPage_v6_0);
router.post('/getWebMainPage_v6_0', getWebMainPage_v6_0);

/**
 * 网页端筛选模板/商品
 *
 * 参数: device	"0 表示从pc来的请求
 * 1 标识一键生成iOS端
 * 2 标识一键生成android端
 * 3  标识一键生成 app 嵌入网页
 * 4 标识一键生成 web 端
 * 5 标识一键生成微信端
 *
 * 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 201 标识利楚商务
 * 301 标识酒单网"
 * 参数: typeLs	 一级分类数组的 json 字符串, 如: “[1,3,5]”, 空数组标识不限
 * 参数: typeMs	 二级分类数组的 json 字符串, 如: “[20,40]”, 空数组标识不限
 * 参数: typeSs	 三级分类数组的 json 字符串, 如: “[40,50]”, 空数组标识不限
 * 参数: tags	 标签id 数组的 json 字符串, 如: “[1,2,3]”, 空数组标识不限
 * 参数: colors	 颜色 id 数组的 json 字符串, 如: “[5,6,7,8]”, 空数组标识不限
 * 参数: pageNum	 页码
 * 参数: pageSize	 页容量
 * 参数: price	-1 不限, 1 免费, 2, vip
 * 参数[可选]: keyword	 关键词(去特殊字符, 以 空格分割, 以 半角 , 拼接), 长度限制20字
 * 参数[取消此参数，固定返回][可选]: withTotalPage	是否获取总页数, 0或不传递, 标识不获取, 1 标识获取
 *
 * 测试地址: http://localhost:3000/v5/tg3/filterDesignAndItem_v6_0?device=1&keyword=
 */
function filterDesignAndItem_v6_0(req, res, next) {

    var typeLs = checkUtil.arrayFromReq(req, 'typeLs');
    var typeMs = checkUtil.arrayFromReq(req, 'typeMs');
    var typeSs = checkUtil.arrayFromReq(req, 'typeSs');
    var tags = checkUtil.arrayFromReq(req, 'tags')||[];
    var colors = checkUtil.arrayFromReq(req, 'colors')||[];
    var price = checkUtil.numberFromReq(req, 'price') ||-1;
    var keyword = checkUtil.stringFromReq(req, 'keyword') || '';
    var withTotalPage = checkUtil.numberFromReq(req, 'withTotalPage') || 0;
    var pageNum = checkUtil.numberFromReq(req, 'pageNum') || 0;
    var pageSize = checkUtil.numberFromReq(req, 'pageSize') || 12;

    if (price == -1){
        price = [0,10];
    }
    if (price == 1){
        price = [0];
    }
    if (price == 2){
        price = [10];
    }
    var kwdIds = null;
    if (tags || colors || tags.length > 0 || colors.length > 0){
        kwdIds =  tags.concat(colors);
    }
    //过滤参数中的特殊字符
    var pattern = new RegExp("[`~!@#$^&*%()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]");
    var keywordRs = "";
    for(var i = 0; i < keyword.length; i++) {
        keywordRs += keyword.substr(i, 1).replace(pattern, '');
    }
    keyword = luaUtil.doSegmentOfText(keywordRs);

    var param={
        typeLs : typeLs || [],
        keyword : keyword || [],
        vip : price,
        orderBy : 0,
        pageNum : pageNum || 0,
        pageSize : pageSize || 0,
        withTotalPage : withTotalPage || 0,
        kwdIds :kwdIds,
        typeMs : typeMs || [],
        typeSs : typeSs || []
    };
    luaUtil.searchUniItemsFromRedis(param,function(err,list){
        if(err){
            console.log("v5/tg3/filterDesignAndItem_v6_0 [searchUniItemsFromRedis] err"+err);
            return tg3Util.ret_func_json(0, "没有获取到数据", {}, res);
        }
        if(!list){
            return tg3Util.ret_func_json(0,"没有获取到数据",{},res);
        }
        var obj = {};
        obj.result = list.list;
        if (withTotalPage) {
            obj.currentPage = pageNum;
            obj.totalPage =list.totalPage;
        }
        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, obj, res);
    });


//    javaSearchProjectUtil.searchUniItemsFromJavaRedis(param, function (error,list) {
//        if(error){
//            console.log("v5/tg3/filterDesignAndItem_v6_0 [searchUniItemsFromRedis] err"+error);
//            return tg3Util.ret_func_json(0, "没有获取到数据", {}, res);
//        }
//        if(!list){
//            return tg3Util.ret_func_json(0,"没有获取到数据",{},res);
//        }
//        var obj = {};
//        obj.result = list.data.list;
//        obj.currentPage = pageNum;
//        obj.totalPage =list.data.totalPage;
//        return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, obj, res);
//    });

   // //参数判断
   // if(pageNum < 0){
   //     return tg3Util.ret_func_json(0,'pageNum错误',{},res);
   // }
   // if(pageSize < 0){
   //     return tg3Util.ret_func_json(0,'pageSize错误',{},res);
   // }
   // if(price!=-1 && price!=1 && price!=2){
   //     return tg3Util.ret_func_json(0,'price错误',{},res);
   // }
   // if (typeLs==null ) {
   //     return tg3Util.ret_func_json(0,'typeLs错误',{},res);
   // }
   // if (typeMs==null ) {
   //     return tg3Util.ret_func_json(0,'typeMs错误',{},res);
   // }
   // if (typeSs==null ) {
   //     return tg3Util.ret_func_json(0,'typeSs错误',{},res);
   // }
   // if (tags==null ) {
   //     return tg3Util.ret_func_json(0,'tags错误',{},res);
   // }
   // if (colors==null ) {
   //     return tg3Util.ret_func_json(0,'colors错误',{},res);
   // }
   //
   //
   // // types
   // var types = [];
   // if (typeSs.length > 0) { // 有子集的话，就优先使用
   //     types = types.concat(typeSs);
   // } else if (typeMs.length > 0) {
   //     types = types.concat(typeMs);
   // } else if (typeLs.length > 0) {
   //     types = types.concat(typeLs);
   // }
   //
   // // labels
   // var labels = [];
   // if (tags.length > 0) {
   //     labels = labels.concat(tags);
   // }
   //
   //
   // // keywords
   // var keywords = "";
   // if (keyword != null) {
   //     var arr = keyword.split(",");
   //     keywords = luaSearchUtil.getKeywordsSync(arr);
   // }
   //
   // var para = {
   //     types: types.join(','),
   //     labels: labels.join(','),
   //     colors: colors.join(','),
   //     price_type: price,
   //     keywords: keywords,
   //     page_num: pageNum,
   //     page_size: pageSize
   // };
   // luaSearchUtil.searchInRedis(para, function (error, data) {
   //     if (error || data == null || data.length != 3) {
   //         console.log(error);
   //         return tg3Util.ret_func_json(0, 'error', {}, res);
   //     }
   //     var obj = {};
   //     obj.result = JSON.parse(data[1]);
   //     obj.currentPage = pageNum;
   //     obj.totalPage = data[2];
   //     return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, obj, res);
   // });
}
router.get('/filterDesignAndItem_v6_0', filterDesignAndItem_v6_0);
router.post('/filterDesignAndItem_v6_0', filterDesignAndItem_v6_0);

/**
 * 获取 app 首页数据 v6.2
 *
 * */
function getMainPage_v6_2(req, res, next) {
    var device = req.body.device || req.query.device;
    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v6_2";
    var para = {
        device: device  // 每种来源记录一份缓存
    };

    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content && CONFIG.DEBUG != 1){ // 有缓存, 且不是本地调试, 直接返回
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                // 热门搜索词
                function(callback){ //*** results[0]
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});
                },
                // banner 图
                function(callback){ //*** results[1]
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)}, true);
                },
                // 快速入口
                function (callback) { //*** results[2]
                    tg3Util.get_fastTrack_v6_1(function(error,data){callback(error,data)});
                },
                // 秒杀
                function(callback){ //*** results[3]
                    tg3Util.get_seckillInfo_v6_1(function(error,data){ callback(error,data)});
                },
                // 热门专题
                function(callback){ //*** results[4]
                    tg3Util.get_specialTopicInfo_v6_1(function(error,data){ callback(error,data)});
                },
                // 场景案例
                function (callback) { //*** results[5]
                    tg3Util.get_sceneList_v5_6(function(error,data){callback(error,data)});
                },
                // ppt
                function(callback){ //*** results[6]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){if(data) {data.title="幻灯片";data.en=CONFIG.CHS_EN.getEn('幻灯片',1);}callback(error,data);});
                },
                // 单页
                function(callback){ //*** results[7]
                    tg3Util.get_hotsPoster_v6_0(function(error,data){callback(error,data);});
                },
                // 名片
                function(callback){ //*** results[8]
                    tg3Util.get_hotsBusinessCard_v6_0(function(error,data){if(data) {data.title="名片";data.en=CONFIG.CHS_EN.getEn('名片',1);}callback(error,data);});
                },
                // 传单
                function(callback){ //*** results[9]
                    tg3Util.get_hotsLeaflet_v6_0(function(error,data){if(data) {data.title="传单";data.en=CONFIG.CHS_EN.getEn('传单',1);}callback(error,data);});
                },
                // 展架
                function (callback) { //*** results[10]
                    tg3Util.get_hotsDisplayRack_v6_0(function(error, data){if(data) {data.title="展架";data.en=CONFIG.CHS_EN.getEn('展架',1);}callback(error,data);});
                },
                // 微信首图
                function (callback) { //*** results[11]
                    tg3Util.get_hotsWechatCoverBigPic_v6_0(function(error,data){callback(error,data);});
                },
                // 微信小图
                function (callback) { //*** results[12]
                    tg3Util.get_hotsWechatCoverSmallPic_v6_0(function(error,data){callback(error,data);});
                },
                // -------------分类--------------
                // 单页分类
                function(callback){ //*** results[13]
                    tg3Util.get_poseterTypeM_v5_1(function(error,data){ callback(error,data)});
                },
                // ppt 分类
                function(callback){ //*** results[14]
                    tg3Util.get_pptType_v5_5(2,function(error,data){ callback(error,data)});
                },
                // 印品分类
                function (callback) { //*** results[15]
                    tg3Util.get_printTypeM_v5_7(function(error, data){callback(error,data)});
                },
                // 社交媒体分类
                function (callback) {  //*** results[16]
                    tg3Util.get_socialMediaTypeM_v5_3(function(error,data){callback(error,data)});
                },

                //----------------------------------------------------v5.7 新增--------------------------------------------------------------------
                // 电商分类
                function (callback) {  //*** results[17]
                    tg3Util.get_eBusinessTypeM_v5_7(function(error,data){callback(error,data)});
                },
                // 停车牌
                function (callback) { //*** results[18]
                    tg3Util.get_hotsStopSign_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝主图
                function (callback) { //*** results[19]
                    tg3Util.get_hotsTaobaoMainPhoto_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝banner
                function (callback) { //*** results[20]
                    tg3Util.get_hotsTaobaoBanner_v6_0(function(error,data){callback(error, data)});
                },
                // 优惠券
                function (callback) { //*** results[21]
                    tg3Util.get_hotsPrintCoupon_v6_0(function(error,data){callback(error, data)});
                },
                // 不干胶
                function (callback) { //*** results[22]
                    tg3Util.get_hotsPrintSticker_v6_0(function(error,data){callback(error, data)});
                },
                // 招贴海报
                function (callback) { //*** results[23]
                    tg3Util.get_hotsPrintPoster_v6_0(function(error,data){callback(error, data)});
                },
                //----------------------------------------------------v6.0 新增--------------------------------------------------------------------
                // 微商分类
                function (callback) { //*** results[24]
                    tg3Util.get_wechatBusiness_v6_0(function(error,data){callback(error,data)});
                },
                // 微商热门
                function (callback) { //*** results[25]
                    tg3Util.get_hotsWechatBusiness_v6_0(function(error,data){callback(error, data)});
                },
                //----------------------------------------------------v6.2 新增--------------------------------------------------------------------
                function (callback) {  //*** results[26]
                    tg3Util.get_vilabInfo_v6_2(function(error,data){callback(error,data)});
                }
            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    //"activityUrl" :            "",
                    "hiddenVoiceInput":        1, // 标记隐藏语音输入___废弃
                    "couponActivity":          0,
                    "hiddenFirstActivity":     1,// 1表示隐藏iOS新安装时的抽奖
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏___废弃
                    "qaVersion" :              1,
                    "serviceTel":             "027-87101355",

                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "adInfo":                  results[1],
                    "fastTrack":               results[2] || [],
                    "seckill":                 results[3],
                    "VILab" :                  null,
                    "specialTopic":           results[4],
                    "scene":                   results[5],
                    "hots": [

                        results[7], // 单页
                        results[6], // ppt
                        results[11], // 微信首图
                        results[12], // 微信小图
                        results[25], // 微商 --
                        results[19], // 淘宝主图
                        results[20], // 淘宝 banner

                        results[8], // 名片 --
                        results[9], // 传单
                        results[10], // 展架
                        results[23], // 招贴海报
                        results[21], //优惠券 --
                        results[22], // 不干胶
                        results[18], // 停车牌 --

                    ],
                    "poseterTypeM":            results[13],         // 海报分类
                    "pptTypeM":                results[14] || [],   // ppt 分类
                    "printTypeM":              results[15],         // 印品分类
                    "socialMediaTypeM":        results[16] || [],   // 社交媒体分类
                    "eBusinessTypeM" :         results[17],         // 电商分类
                    "wechatBusiness" :         results[24]          // 微商分类
                };

                // 热门系列截断, 保持列数显示两行
                var row = 2;
                for(var i = 0; i < data.hots.length; i++) {
                    var obj = data.hots[i];
                    if(obj && obj.list) {
                        obj.list = obj.list.slice(0, Math.floor(obj.column)*row);
                    }
                }
                data.dailyFreeCnt = 100;
                // 测试环境限制调大
                if(CONFIG.DEBUG) {
                    data.dailyFreeCnt = 1000;
                }
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v6_2', getMainPage_v6_2);
router.post('/getMainPage_v6_2', getMainPage_v6_2);

/**
 * 获取 app 开屏广告位信息
 *
 * 参数: device	"0表示从p0 表示从pc来的请求
 * 1 标识一键生成iOS端
 * 2 标识一键生成android端
 * 3  标识一键生成 app 嵌入网页
 * 4 标识一键生成 web 端
 * 5 标识一键生成微信端
 *
 * 101 表示pc美化大师/102表示pc wps/103表示wps android/104表示wps ios
 * 201 标识利楚商务
 * 301 标识酒单网"
 * 参数: screenW	APP 屏幕宽(单位: px)
 * 参数: screenH	APP 屏幕高(单位: px)
 * 返回结果:	"{
 *   "success" : 1,
 *   "msg" : "成功",
 *   "data" : {
 *       "kind" : 1, // 开屏广告类型, 暂定 1 为广告图片显示, 当前版本若不为1则不处理
 *       "url" : "", // 广告详情跳转页面(使用 banner 图的 webview, 暂不处理)
 *       "imgUrl" : "http://oss-img.jpg", // 图片地址
 *       "imgW" : 750, // 广告图宽
 *       "imgH" : 1334, // 广告图高
 *       "displayTime" : 3, // 开屏广告的展示默认时长(单位: 秒)
 *       "displayInterval" : 30000000, // 两次开屏广告展示的最小间隔(单位: 秒)
 *    }
 * }"
 *
 * 测试地址: http://localhost:3000/v5/tg3/getAppAdInfo_v6_2?device=4&screenW=750&screenH=1334
 * */
function getAppAdInfo_v6_2(req, res, next) {

    var device = checkUtil.numberFromReq(req, 'device');
    var screenW = checkUtil.numberFromReq(req, 'screenW');
    var screenH = checkUtil.numberFromReq(req, 'screenH');
    if(screenW <= 0 || screenH <= 0) {
        return tg3Util.ret_func_json(0, '参数错误', {}, res);
    }
    var uri = '/v5/tg3/getAppAdInfo_v6_2';
    var para = {
        device:device,
        screenW: screenW,
        screenH: screenH
    };
    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content && CONFIG.DEBUG != 1){ // 有缓存, 且不是本地调试, 直接返回
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }
        tg3Util.getAppAdInfo_v6_2(screenW, screenH, function(error, info){
            if(error) {
                console.log('/v5/tg3.js [getAppAdInfo_v6_2] err: ' + error);
                return tg3Util.ret_func_json(0, CODE.OPERATION_FAILED, {}, res);
            }

            var content = StaticizeUtil.recordByRedis(__filename, uri, para, info);  // 缓存
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, info, res);
        });
    });
}
router.get('/getAppAdInfo_v6_2', getAppAdInfo_v6_2);
router.post('/getAppAdInfo_v6_2', getAppAdInfo_v6_2);

/**
 * 获取 app 首页数据 v6.2
 *
 * */
function getMainPage_v6_3(req, res, next) {
    var device = req.body.device || req.query.device;
    // 优先使用缓存
    var uri = "/v5/tg3/getMainPage_v6_3";
    var para = {
        device: device  // 每种来源记录一份缓存
    };

    StaticizeUtil.getByRedis(__filename, uri, para, function(error, content){
        if(content && CONFIG.DEBUG != 1){ // 有缓存, 且不是本地调试, 直接返回
            return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
        }

        async.series([
                // 热门搜索词
                function(callback){ //*** results[0]
                    tg3Util.get_hotsSearch(null, function(error,data){ callback(error,data)});
                },
                // banner 图
                function(callback){ //*** results[1]
                    tg3Util.get_adInfo_v5_1(function(error,data){ callback(error,data)}, true);
                },
                // 快速入口
                function (callback) { //*** results[2]
                    tg3Util.get_fastTrack_v6_1(function(error,data){callback(error,data)});
                },
                // 秒杀
                function(callback){ //*** results[3]
                    tg3Util.get_seckillInfo_v6_1(function(error,data){ callback(error,data)});
                },
                // 热门专题
                function(callback){ //*** results[4]
                    tg3Util.get_specialTopicInfo_v6_1(function(error,data){ callback(error,data)});
                },
                // 场景案例
                function (callback) { //*** results[5]
                    tg3Util.get_sceneList_v5_6(function(error,data){callback(error,data)});
                },
                // ppt
                function(callback){ //*** results[6]
                    tg3Util.get_hotsPPT_v5_3(function(error,data){if(data) {data.title="幻灯片";data.en=CONFIG.CHS_EN.getEn('幻灯片',1);}callback(error,data);});
                },
                // 单页
                function(callback){ //*** results[7]
                    tg3Util.get_hotsPoster_v6_0(function(error,data){callback(error,data);});
                },
                // 名片
                function(callback){ //*** results[8]
                    tg3Util.get_hotsBusinessCard_v6_0(function(error,data){if(data) {data.title="名片";data.en=CONFIG.CHS_EN.getEn('名片',1);}callback(error,data);});
                },
                // 传单
                function(callback){ //*** results[9]
                    tg3Util.get_hotsLeaflet_v6_0(function(error,data){if(data) {data.title="传单";data.en=CONFIG.CHS_EN.getEn('传单',1);}callback(error,data);});
                },
                // 展架
                function (callback) { //*** results[10]
                    tg3Util.get_hotsDisplayRack_v6_0(function(error, data){if(data) {data.title="展架";data.en=CONFIG.CHS_EN.getEn('展架',1);}callback(error,data);});
                },
                // 微信首图
                function (callback) { //*** results[11]
                    tg3Util.get_hotsWechatCoverBigPic_v6_0(function(error,data){callback(error,data);});
                },
                // 微信小图
                function (callback) { //*** results[12]
                    tg3Util.get_hotsWechatCoverSmallPic_v6_0(function(error,data){callback(error,data);});
                },
                // 停车牌
                function (callback) { //*** results[13]
                    tg3Util.get_hotsStopSign_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝主图
                function (callback) { //*** results[14]
                    tg3Util.get_hotsTaobaoMainPhoto_v6_0(function(error,data){callback(error, data)});
                },
                // 淘宝banner
                function (callback) { //*** results[15]
                    tg3Util.get_hotsTaobaoBanner_v6_0(function(error,data){callback(error, data)});
                },
                // 优惠券
                function (callback) { //*** results[16]
                    tg3Util.get_hotsPrintCoupon_v6_0(function(error,data){callback(error, data)});
                },
                // 不干胶
                function (callback) { //*** results[17]
                    tg3Util.get_hotsPrintSticker_v6_0(function(error,data){callback(error, data)});
                },
                // 招贴海报
                function (callback) { //*** results[18]
                    tg3Util.get_hotsPrintPoster_v6_0(function(error,data){callback(error, data)});
                },
                // 微商热门
                function (callback) { //*** results[19]
                    tg3Util.get_hotsWechatBusiness_v6_0(function(error,data){callback(error, data)});
                },
                // vi 实验室
                function (callback) {  //*** results[20]
                    tg3Util.get_vilabInfo_v6_2(function(error,data){callback(error,data)});
                },
                // 分类信息
                function(callback) { //*** results[21]
                    tg3Util.get_appTypesInfo(function(error,data){callback(error,data)});
                }
            ],
            // 返回
            function(err, results){
                if(err){
                    console.log(err);
                    return tg3Util.ret_func_json(0,'error',{},res);
                }

                var data = {
                    //"activityUrl" :            "",
                    "hiddenVoiceInput":        1, // 标记隐藏语音输入___废弃
                    "couponActivity":          0,
                    "hiddenFirstActivity":     1,// 1表示隐藏iOS新安装时的抽奖
                    "hiddenPartner" :          0, // 城市合伙人是否隐藏___废弃
                    "qaVersion" :              1,
                    "serviceTel":             "027-87101355",

                    "hotsSearch":              results[0].length>0?results[0][0]:'',
                    "adInfo":                  results[1],
                    "fastTrack":               results[2] || [],
                    "seckill":                 results[3],
                    "VILab" :                  null,
                    "specialTopic":            results[4],
                    "scene":                   results[5],
                    "hots": [
                        results[7], // 单页
                        results[6], // ppt
                        results[11], // 微信首图
                        results[12], // 微信小图
                        results[19], // 微商 --
                        results[14], // 淘宝主图
                        results[15], // 淘宝 banner

                        results[8], // 名片 --
                        results[9], // 传单
                        results[10], // 展架
                        results[18], // 招贴海报
                        results[16], //优惠券 --
                        results[17], // 不干胶
                        results[13], // 停车牌 --
                    ],
                    types : results[21] || [] // 分类树
                };

                // 热门系列截断, 保持列数显示两行
                var row = 2;
                for(var i = 0; i < data.hots.length; i++) {
                    var obj = data.hots[i];
                    if(obj && obj.list) {
                        obj.list = obj.list.slice(0, Math.floor(obj.column)*row);
                    }
                }
                data.dailyFreeCnt = 100;
                // 测试环境限制调大
                if(CONFIG.DEBUG) {
                    data.dailyFreeCnt = 1000;
                }
                var content = StaticizeUtil.recordByRedis(__filename, uri, para, data);  // 缓存
                return tg3Util.ret_func_json(1, CODE.OPERATION_SUCCESS, content, res);
            });
    });
}
router.get('/getMainPage_v6_3', getMainPage_v6_3);
router.post('/getMainPage_v6_3', getMainPage_v6_3);

//===============================================================================================
module.exports = router;